From 4ba579bc25ab2bbde370231d090588c237552c76 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 15 Dec 2019 11:41:21 +0000 Subject: Also allow #no_bounds_check on an expression #499 --- src/check_expr.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/check_expr.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 6e6db24d1..0ee604283 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -3052,7 +3052,7 @@ bool check_index_value(CheckerContext *c, bool open_range, Ast *index_value, i64 } if (operand.mode == Addressing_Constant && - (c->stmt_state_flags & StmtStateFlag_no_bounds_check) == 0) { + (c->state_flags & StateFlag_no_bounds_check) == 0) { BigInt i = exact_value_to_integer(operand.value).value_integer; if (i.neg) { gbString expr_str = expr_to_string(operand.expr); @@ -6974,6 +6974,24 @@ bool check_range(CheckerContext *c, Ast *node, Operand *x, Operand *y, ExactValu ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { + u32 prev_state_flags = c->state_flags; + defer (c->state_flags = prev_state_flags); + if (node->state_flags != 0) { + u32 in = node->state_flags; + u32 out = c->state_flags; + + if (in & StateFlag_no_bounds_check) { + out |= StateFlag_no_bounds_check; + out &= ~StateFlag_bounds_check; + } else if (in & StateFlag_bounds_check) { + out |= StateFlag_bounds_check; + out &= ~StateFlag_no_bounds_check; + } + + c->state_flags = out; + } + + ExprKind kind = Expr_Stmt; o->mode = Addressing_Invalid; -- cgit v1.2.3