authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-27 09:52:49-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-27 09:52:49-05:00
logd8965002593c111069862e7de06402ee77b2b614
treec6b5c3e9dc2aedc278c70620abd0277cf089c4bf
parent4591389497b9bb362cb9385506b6cdc629eae8ea
parentf41e50dc08e5e701631e96d4fa278866a08a98d9
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'LemonBoy-fix-4274'


2 files changed, 33 insertions(+), 14 deletions(-)

src/ir.cpp+27-14
...@@ -271,6 +271,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,...@@ -271,6 +271,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
271 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type);271 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type);
272static ResultLoc *no_result_loc(void);272static ResultLoc *no_result_loc(void);
273static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);273static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);
274static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);
274275
275static void destroy_instruction_src(IrInstSrc *inst) {276static void destroy_instruction_src(IrInstSrc *inst) {
276#ifdef ZIG_ENABLE_MEM_PROFILE277#ifdef ZIG_ENABLE_MEM_PROFILE
...@@ -20999,8 +21000,13 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -20999,8 +21000,13 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20999 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);21000 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
21000 if (tld->resolution == TldResolutionInvalid)21001 if (tld->resolution == TldResolutionInvalid)
21001 return ira->codegen->invalid_inst_gen;21002 return ira->codegen->invalid_inst_gen;
21003 if (tld->resolution == TldResolutionResolving)
21004 return ir_error_dependency_loop(ira, source_instr);
21005
21002 TldFn *tld_fn = (TldFn *)tld;21006 TldFn *tld_fn = (TldFn *)tld;
21003 ZigFn *fn_entry = tld_fn->fn_entry;21007 ZigFn *fn_entry = tld_fn->fn_entry;
21008 assert(fn_entry != nullptr);
21009
21004 if (type_is_invalid(fn_entry->type_entry))21010 if (type_is_invalid(fn_entry->type_entry))
21005 return ira->codegen->invalid_inst_gen;21011 return ira->codegen->invalid_inst_gen;
2100621012
...@@ -21010,8 +21016,13 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -21010,8 +21016,13 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
21010 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);21016 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
21011 if (tld->resolution == TldResolutionInvalid)21017 if (tld->resolution == TldResolutionInvalid)
21012 return ira->codegen->invalid_inst_gen;21018 return ira->codegen->invalid_inst_gen;
21019 if (tld->resolution == TldResolutionResolving)
21020 return ir_error_dependency_loop(ira, source_instr);
21021
21013 TldVar *tld_var = (TldVar *)tld;21022 TldVar *tld_var = (TldVar *)tld;
21014 ZigVar *var = tld_var->var;21023 ZigVar *var = tld_var->var;
21024 assert(var != nullptr);
21025
21015 if (type_is_invalid(var->var_type))21026 if (type_is_invalid(var->var_type))
21016 return ira->codegen->invalid_inst_gen;21027 return ira->codegen->invalid_inst_gen;
2101721028
...@@ -21334,6 +21345,8 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction...@@ -21334,6 +21345,8 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction
21334 if (tld->resolution == TldResolutionInvalid) {21345 if (tld->resolution == TldResolutionInvalid) {
21335 return ira->codegen->invalid_inst_gen;21346 return ira->codegen->invalid_inst_gen;
21336 }21347 }
21348 if (tld->resolution == TldResolutionResolving)
21349 return ir_error_dependency_loop(ira, source_instruction);
2133721350
21338 switch (tld->id) {21351 switch (tld->id) {
21339 case TldIdContainer:21352 case TldIdContainer:
...@@ -21343,9 +21356,8 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction...@@ -21343,9 +21356,8 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction
21343 case TldIdVar: {21356 case TldIdVar: {
21344 TldVar *tld_var = (TldVar *)tld;21357 TldVar *tld_var = (TldVar *)tld;
21345 ZigVar *var = tld_var->var;21358 ZigVar *var = tld_var->var;
21346 if (var == nullptr) {21359 assert(var != nullptr);
21347 return ir_error_dependency_loop(ira, source_instruction);21360
21348 }
21349 if (tld_var->extern_lib_name != nullptr) {21361 if (tld_var->extern_lib_name != nullptr) {
21350 add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name),21362 add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name),
21351 source_instruction->source_node);21363 source_instruction->source_node);
...@@ -21356,7 +21368,7 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction...@@ -21356,7 +21368,7 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction
21356 case TldIdFn: {21368 case TldIdFn: {
21357 TldFn *tld_fn = (TldFn *)tld;21369 TldFn *tld_fn = (TldFn *)tld;
21358 ZigFn *fn_entry = tld_fn->fn_entry;21370 ZigFn *fn_entry = tld_fn->fn_entry;
21359 assert(fn_entry->type_entry);21371 assert(fn_entry->type_entry != nullptr);
2136021372
21361 if (type_is_invalid(fn_entry->type_entry))21373 if (type_is_invalid(fn_entry->type_entry))
21362 return ira->codegen->invalid_inst_gen;21374 return ira->codegen->invalid_inst_gen;
...@@ -23536,11 +23548,14 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -23536,11 +23548,14 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2353623548
23537 while ((curr_entry = decl_it.next()) != nullptr) {23549 while ((curr_entry = decl_it.next()) != nullptr) {
23538 // If the declaration is unresolved, force it to be resolved again.23550 // If the declaration is unresolved, force it to be resolved again.
23539 if (curr_entry->value->resolution == TldResolutionUnresolved) {23551 resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false);
23540 resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false);23552 if (curr_entry->value->resolution == TldResolutionInvalid) {
23541 if (curr_entry->value->resolution != TldResolutionOk) {23553 return ErrorSemanticAnalyzeFail;
23542 return ErrorSemanticAnalyzeFail;23554 }
23543 }23555
23556 if (curr_entry->value->resolution == TldResolutionResolving) {
23557 ir_error_dependency_loop(ira, source_instr);
23558 return ErrorSemanticAnalyzeFail;
23544 }23559 }
2354523560
23546 // Skip comptime blocks and test functions.23561 // Skip comptime blocks and test functions.
...@@ -23597,6 +23612,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -23597,6 +23612,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
23597 case TldIdVar:23612 case TldIdVar:
23598 {23613 {
23599 ZigVar *var = ((TldVar *)curr_entry->value)->var;23614 ZigVar *var = ((TldVar *)curr_entry->value)->var;
23615 assert(var != nullptr);
23616
23600 if ((err = type_resolve(ira->codegen, var->const_value->type, ResolveStatusSizeKnown)))23617 if ((err = type_resolve(ira->codegen, var->const_value->type, ResolveStatusSizeKnown)))
23601 return ErrorSemanticAnalyzeFail;23618 return ErrorSemanticAnalyzeFail;
2360223619
...@@ -23627,11 +23644,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -23627,11 +23644,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2362723644
23628 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;23645 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
23629 assert(!fn_entry->is_test);23646 assert(!fn_entry->is_test);
2363023647 assert(fn_entry->type_entry != nullptr);
23631 if (fn_entry->type_entry == nullptr) {
23632 ir_error_dependency_loop(ira, source_instr);
23633 return ErrorSemanticAnalyzeFail;
23634 }
2363523648
23636 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;23649 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;
2363723650
test/compile_errors.zig+6
...@@ -3,6 +3,12 @@ const builtin = @import("builtin");...@@ -3,6 +3,12 @@ const builtin = @import("builtin");
3const Target = @import("std").Target;3const Target = @import("std").Target;
44
5pub fn addCases(cases: *tests.CompileErrorContext) void {5pub fn addCases(cases: *tests.CompileErrorContext) void {
6 cases.addTest("dependency loop in top-level decl with @TypeInfo",
7 \\export const foo = @typeInfo(@This());
8 , &[_][]const u8{
9 "tmp.zig:1:20: error: dependency loop detected",
10 });
11
6 cases.addTest("non-exhaustive enums",12 cases.addTest("non-exhaustive enums",
7 \\const A = enum {13 \\const A = enum {
8 \\ a,14 \\ a,