| ... | @@ -5325,15 +5325,19 @@ static void add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg | ... | @@ -5325,15 +5325,19 @@ static void add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg |
| 5325 | add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1); | 5325 | add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1); |
| 5326 | } | 5326 | } |
| 5327 | | 5327 | |
| 5328 | static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) { | 5328 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg) { |
| 5329 | ira->new_irb.exec->invalid = true; | 5329 | exec->invalid = true; |
| 5330 | ErrorMsg *err_msg = add_node_error(ira->codegen, source_node, msg); | 5330 | ErrorMsg *err_msg = add_node_error(codegen, source_node, msg); |
| 5331 | if (ira->new_irb.exec->parent_exec) { | 5331 | if (exec->parent_exec) { |
| 5332 | add_call_stack_errors(ira->codegen, ira->new_irb.exec, err_msg, 10); | 5332 | add_call_stack_errors(codegen, exec, err_msg, 10); |
| 5333 | } | 5333 | } |
| 5334 | return err_msg; | 5334 | return err_msg; |
| 5335 | } | 5335 | } |
| 5336 | | 5336 | |
| | 5337 | static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) { |
| | 5338 | return exec_add_error_node(ira->codegen, ira->new_irb.exec, source_node, msg); |
| | 5339 | } |
| | 5340 | |
| 5337 | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) { | 5341 | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) { |
| 5338 | return ir_add_error_node(ira, source_instruction->source_node, msg); | 5342 | return ir_add_error_node(ira, source_instruction->source_node, msg); |
| 5339 | } | 5343 | } |
| ... | @@ -5345,10 +5349,7 @@ static void ir_add_typedef_err_note(IrAnalyze *ira, ErrorMsg *msg, TypeTableEntr | ... | @@ -5345,10 +5349,7 @@ static void ir_add_typedef_err_note(IrAnalyze *ira, ErrorMsg *msg, TypeTableEntr |
| 5345 | } | 5349 | } |
| 5346 | } | 5350 | } |
| 5347 | | 5351 | |
| 5348 | static IrInstruction *ir_exec_const_result(IrExecutable *exec) { | 5352 | static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 5349 | if (exec->basic_block_list.length != 1) | | |
| 5350 | return nullptr; | | |
| 5351 | | | |
| 5352 | IrBasicBlock *bb = exec->basic_block_list.at(0); | 5353 | IrBasicBlock *bb = exec->basic_block_list.at(0); |
| 5353 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { | 5354 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { |
| 5354 | IrInstruction *instruction = bb->instruction_list.at(i); | 5355 | IrInstruction *instruction = bb->instruction_list.at(i); |
| ... | @@ -5356,14 +5357,18 @@ static IrInstruction *ir_exec_const_result(IrExecutable *exec) { | ... | @@ -5356,14 +5357,18 @@ static IrInstruction *ir_exec_const_result(IrExecutable *exec) { |
| 5356 | IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction; | 5357 | IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction; |
| 5357 | IrInstruction *value = ret_inst->value; | 5358 | IrInstruction *value = ret_inst->value; |
| 5358 | if (value->value.special == ConstValSpecialRuntime) { | 5359 | if (value->value.special == ConstValSpecialRuntime) { |
| 5359 | return nullptr; | 5360 | exec_add_error_node(codegen, exec, value->source_node, |
| | 5361 | buf_sprintf("unable to evaluate constant expression")); |
| | 5362 | return codegen->invalid_instruction; |
| 5360 | } | 5363 | } |
| 5361 | return value; | 5364 | return value; |
| 5362 | } else if (ir_has_side_effects(instruction)) { | 5365 | } else if (ir_has_side_effects(instruction)) { |
| 5363 | return nullptr; | 5366 | exec_add_error_node(codegen, exec, instruction->source_node, |
| | 5367 | buf_sprintf("unable to evaluate constant expression")); |
| | 5368 | return codegen->invalid_instruction; |
| 5364 | } | 5369 | } |
| 5365 | } | 5370 | } |
| 5366 | return nullptr; | 5371 | zig_unreachable(); |
| 5367 | } | 5372 | } |
| 5368 | | 5373 | |
| 5369 | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) { | 5374 | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) { |
| ... | @@ -5968,13 +5973,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node | ... | @@ -5968,13 +5973,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node |
| 5968 | fprintf(stderr, "}\n"); | 5973 | fprintf(stderr, "}\n"); |
| 5969 | } | 5974 | } |
| 5970 | | 5975 | |
| 5971 | IrInstruction *result = ir_exec_const_result(&analyzed_executable); | 5976 | return ir_exec_const_result(codegen, &analyzed_executable); |
| 5972 | if (!result) { | | |
| 5973 | add_node_error(codegen, source_node, buf_sprintf("unable to evaluate constant expression")); | | |
| 5974 | return codegen->invalid_instruction; | | |
| 5975 | } | | |
| 5976 | | | |
| 5977 | return result; | | |
| 5978 | } | 5977 | } |
| 5979 | | 5978 | |
| 5980 | static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { | 5979 | static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { |