authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-25 16:04:01-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-25 16:04:01-04:00
logda68aec3393648fd89262b2142766d9f734720dc
tree224cd251b363dd4b2a32d19121bc695a87bc800c
parentcb55803a59d4fe99b527dc3ffc5674666511f729
signaturelock-open Commit is signed but in an unrecognized format.

fix infinite loop when error in peer resolution


1 files changed, 21 insertions(+), 8 deletions(-)

src/ir.cpp+21-8
...@@ -203,7 +203,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c...@@ -203,7 +203,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
203 assert(get_src_ptr_type(const_val->type) != nullptr);203 assert(get_src_ptr_type(const_val->type) != nullptr);
204 assert(const_val->special == ConstValSpecialStatic);204 assert(const_val->special == ConstValSpecialStatic);
205 ConstExprValue *result;205 ConstExprValue *result;
206 206
207 switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {207 switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {
208 case OnePossibleValueInvalid:208 case OnePossibleValueInvalid:
209 zig_unreachable();209 zig_unreachable();
...@@ -215,7 +215,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c...@@ -215,7 +215,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
215 case OnePossibleValueNo:215 case OnePossibleValueNo:
216 break;216 break;
217 }217 }
218 218
219 switch (const_val->data.x_ptr.special) {219 switch (const_val->data.x_ptr.special) {
220 case ConstPtrSpecialInvalid:220 case ConstPtrSpecialInvalid:
221 zig_unreachable();221 zig_unreachable();
...@@ -4242,7 +4242,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode...@@ -4242,7 +4242,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
4242 TldVar *tld_var = allocate<TldVar>(1);4242 TldVar *tld_var = allocate<TldVar>(1);
4243 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);4243 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
4244 tld_var->base.resolution = TldResolutionInvalid;4244 tld_var->base.resolution = TldResolutionInvalid;
4245 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false, 4245 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,
4246 &g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid);4246 &g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid);
4247 scope_decls->decl_table.put(var_name, &tld_var->base);4247 scope_decls->decl_table.put(var_name, &tld_var->base);
4248}4248}
...@@ -11031,7 +11031,7 @@ static void ir_start_next_bb(IrAnalyze *ira) {...@@ -11031,7 +11031,7 @@ static void ir_start_next_bb(IrAnalyze *ira) {
11031 ira->old_bb_index += 1;11031 ira->old_bb_index += 1;
11032 continue;11032 continue;
11033 }11033 }
11034 // if it's already started, or 11034 // if it's already started, or
11035 // if it's a suspended block,11035 // if it's a suspended block,
11036 // then skip it11036 // then skip it
11037 if (old_bb->suspended ||11037 if (old_bb->suspended ||
...@@ -13259,7 +13259,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -13259,7 +13259,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
13259 } else {13259 } else {
13260 return is_non_null;13260 return is_non_null;
13261 }13261 }
13262 } else if (is_equality_cmp && 13262 } else if (is_equality_cmp &&
13263 ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdPointer &&13263 ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdPointer &&
13264 op2->value.type->data.pointer.ptr_len == PtrLenC) ||13264 op2->value.type->data.pointer.ptr_len == PtrLenC) ||
13265 (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdPointer &&13265 (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdPointer &&
...@@ -16822,6 +16822,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -16822,6 +16822,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
16822 peer_parent->done_resuming = true;16822 peer_parent->done_resuming = true;
16823 return ira_resume(ira);16823 return ira_resume(ira);
16824 }16824 }
16825 if (peer_parent != nullptr && !peer_parent->skipped && peer_parent->base.resolved_loc != nullptr &&
16826 type_is_invalid(peer_parent->base.resolved_loc->value.type))
16827 {
16828 return ira->codegen->invalid_instruction;
16829 }
1682516830
16826 ZigList<IrBasicBlock*> new_incoming_blocks = {0};16831 ZigList<IrBasicBlock*> new_incoming_blocks = {0};
16827 ZigList<IrInstruction*> new_incoming_values = {0};16832 ZigList<IrInstruction*> new_incoming_values = {0};
...@@ -20966,7 +20971,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -20966,7 +20971,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
20966 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err)));20971 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err)));
20967 return ira->codegen->invalid_instruction;20972 return ira->codegen->invalid_instruction;
20968 }20973 }
20969 20974
20970 if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) {20975 if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) {
20971 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err)));20976 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err)));
20972 return ira->codegen->invalid_instruction;20977 return ira->codegen->invalid_instruction;
...@@ -21933,7 +21938,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -21933,7 +21938,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
21933 return ira->codegen->invalid_instruction;21938 return ira->codegen->invalid_instruction;
2193421939
21935 // TODO test this at comptime with u8 and non-u8 types21940 // TODO test this at comptime with u8 and non-u8 types
21936 // TODO test with dest ptr being a global runtime variable 21941 // TODO test with dest ptr being a global runtime variable
21937 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&21942 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
21938 casted_src_ptr->value.special == ConstValSpecialStatic &&21943 casted_src_ptr->value.special == ConstValSpecialStatic &&
21939 casted_count->value.special == ConstValSpecialStatic &&21944 casted_count->value.special == ConstValSpecialStatic &&
...@@ -24789,7 +24794,15 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct...@@ -24789,7 +24794,15 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
24789 return result_loc;24794 return result_loc;
2479024795
24791 if (!was_written) {24796 if (!was_written) {
24792 ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);24797 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);
24798 if (type_is_invalid(store_ptr->value.type)) {
24799 instruction->result_loc->resolved_loc = ira->codegen->invalid_instruction;
24800 if (instruction->result_loc->id == ResultLocIdPeer) {
24801 reinterpret_cast<ResultLocPeer *>(instruction->result_loc)->parent->base.resolved_loc =
24802 ira->codegen->invalid_instruction;
24803 }
24804 return ira->codegen->invalid_instruction;
24805 }
24793 }24806 }
2479424807
24795 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {24808 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {