| ... | ... | @@ -567,12 +567,13 @@ static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, Scope *scope, Ast |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id, |
| 570 | | IrInstruction *op1, IrInstruction *op2) |
| 570 | IrInstruction *op1, IrInstruction *op2, bool safety_check_on) |
| 571 | 571 | { |
| 572 | 572 | IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(irb, scope, source_node); |
| 573 | 573 | bin_op_instruction->op_id = op_id; |
| 574 | 574 | bin_op_instruction->op1 = op1; |
| 575 | 575 | bin_op_instruction->op2 = op2; |
| 576 | bin_op_instruction->safety_check_on = safety_check_on; |
| 576 | 577 | |
| 577 | 578 | ir_ref_instruction(op1); |
| 578 | 579 | ir_ref_instruction(op2); |
| ... | ... | @@ -581,10 +582,10 @@ static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *sou |
| 581 | 582 | } |
| 582 | 583 | |
| 583 | 584 | static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_instruction, IrBinOp op_id, |
| 584 | | IrInstruction *op1, IrInstruction *op2) |
| 585 | IrInstruction *op1, IrInstruction *op2, bool safety_check_on) |
| 585 | 586 | { |
| 586 | 587 | IrInstruction *new_instruction = ir_build_bin_op(irb, old_instruction->scope, |
| 587 | | old_instruction->source_node, op_id, op1, op2); |
| 588 | old_instruction->source_node, op_id, op1, op2, safety_check_on); |
| 588 | 589 | ir_link_new_instruction(new_instruction, old_instruction); |
| 589 | 590 | return new_instruction; |
| 590 | 591 | } |
| ... | ... | @@ -1455,7 +1456,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 1455 | 1456 | static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 1456 | 1457 | IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 1457 | 1458 | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 1458 | | return ir_build_bin_op(irb, scope, node, op_id, op1, op2); |
| 1459 | return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); |
| 1459 | 1460 | } |
| 1460 | 1461 | |
| 1461 | 1462 | static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) { |
| ... | ... | @@ -1479,7 +1480,7 @@ static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *no |
| 1479 | 1480 | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 1480 | 1481 | if (op2 == irb->codegen->invalid_instruction) |
| 1481 | 1482 | return op2; |
| 1482 | | IrInstruction *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2); |
| 1483 | IrInstruction *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); |
| 1483 | 1484 | ir_build_store_ptr(irb, scope, node, lvalue, result); |
| 1484 | 1485 | return ir_build_const_void(irb, scope, node); |
| 1485 | 1486 | } |
| ... | ... | @@ -2322,11 +2323,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 2322 | 2323 | |
| 2323 | 2324 | ir_set_cursor_at_end(irb, cond_block); |
| 2324 | 2325 | IrInstruction *index_val = ir_build_load_ptr(irb, child_scope, node, index_ptr); |
| 2325 | | IrInstruction *cond = ir_build_bin_op(irb, child_scope, node, IrBinOpCmpLessThan, index_val, len_val); |
| 2326 | IrInstruction *cond = ir_build_bin_op(irb, child_scope, node, IrBinOpCmpLessThan, index_val, len_val, false); |
| 2326 | 2327 | ir_build_cond_br(irb, child_scope, node, cond, body_block, end_block, is_inline); |
| 2327 | 2328 | |
| 2328 | 2329 | ir_set_cursor_at_end(irb, body_block); |
| 2329 | | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, child_scope, node, array_val_ptr, index_val, true); |
| 2330 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, child_scope, node, array_val_ptr, index_val, false); |
| 2330 | 2331 | IrInstruction *elem_val; |
| 2331 | 2332 | if (node->data.for_expr.elem_is_ptr) { |
| 2332 | 2333 | elem_val = elem_ptr; |
| ... | ... | @@ -2345,7 +2346,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 2345 | 2346 | ir_build_br(irb, child_scope, node, continue_block, is_inline); |
| 2346 | 2347 | |
| 2347 | 2348 | ir_set_cursor_at_end(irb, continue_block); |
| 2348 | | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one); |
| 2349 | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); |
| 2349 | 2350 | ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val); |
| 2350 | 2351 | ir_build_br(irb, child_scope, node, cond_block, is_inline); |
| 2351 | 2352 | |
| ... | ... | @@ -2654,13 +2655,13 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 2654 | 2655 | IrInstruction *end_value_const = ir_build_static_eval(irb, scope, start_node, end_value); |
| 2655 | 2656 | |
| 2656 | 2657 | IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq, |
| 2657 | | target_value, start_value_const); |
| 2658 | target_value, start_value_const, false); |
| 2658 | 2659 | IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq, |
| 2659 | | target_value, end_value_const); |
| 2660 | target_value, end_value_const, false); |
| 2660 | 2661 | IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd, |
| 2661 | | lower_range_ok, upper_range_ok); |
| 2662 | lower_range_ok, upper_range_ok, false); |
| 2662 | 2663 | if (ok_bit) { |
| 2663 | | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit); |
| 2664 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false); |
| 2664 | 2665 | } else { |
| 2665 | 2666 | ok_bit = both_ok; |
| 2666 | 2667 | } |
| ... | ... | @@ -2670,9 +2671,9 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 2670 | 2671 | return irb->codegen->invalid_instruction; |
| 2671 | 2672 | |
| 2672 | 2673 | IrInstruction *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq, |
| 2673 | | item_value, target_value); |
| 2674 | item_value, target_value, false); |
| 2674 | 2675 | if (ok_bit) { |
| 2675 | | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit); |
| 2676 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false); |
| 2676 | 2677 | } else { |
| 2677 | 2678 | ok_bit = cmp_ok; |
| 2678 | 2679 | } |
| ... | ... | @@ -4027,7 +4028,8 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 4027 | 4028 | return bool_type; |
| 4028 | 4029 | } |
| 4029 | 4030 | |
| 4030 | | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, bin_op_instruction->op_id, casted_op1, casted_op2); |
| 4031 | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, bin_op_instruction->op_id, |
| 4032 | casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 4031 | 4033 | return bool_type; |
| 4032 | 4034 | } |
| 4033 | 4035 | |
| ... | ... | @@ -4145,7 +4147,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 4145 | 4147 | return ira->codegen->builtin_types.entry_bool; |
| 4146 | 4148 | } |
| 4147 | 4149 | |
| 4148 | | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id, casted_op1, casted_op2); |
| 4150 | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id, |
| 4151 | casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 4149 | 4152 | |
| 4150 | 4153 | return ira->codegen->builtin_types.entry_bool; |
| 4151 | 4154 | } |
| ... | ... | @@ -4311,7 +4314,8 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 4311 | 4314 | |
| 4312 | 4315 | } |
| 4313 | 4316 | |
| 4314 | | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id, casted_op1, casted_op2); |
| 4317 | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id, |
| 4318 | casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 4315 | 4319 | return resolved_type; |
| 4316 | 4320 | } |
| 4317 | 4321 | |
| ... | ... | @@ -5345,7 +5349,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 5345 | 5349 | if (casted_elem_index == ira->codegen->invalid_instruction) |
| 5346 | 5350 | return ira->codegen->builtin_types.entry_invalid; |
| 5347 | 5351 | |
| 5348 | | bool safety_check_on = true; |
| 5352 | bool safety_check_on = elem_ptr_instruction->safety_check_on; |
| 5349 | 5353 | if (casted_elem_index->static_value.special != ConstValSpecialRuntime) { |
| 5350 | 5354 | uint64_t index = casted_elem_index->static_value.data.x_bignum.data.x_uint; |
| 5351 | 5355 | if (array_type->id == TypeTableEntryIdArray) { |