authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-16 14:02:00-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-16 14:31:41-04:00
logc6e77f248d3771070162d80341f9aeef89a49924
treee9b6b90577552d1447408ce5a147d22af44d49e5
parent1cefe1442450961a7960fa3b4b488ae50d5abbef
signaturelock-open Commit is signed but in an unrecognized format.

fix tripping llvm assert

``` Assertion `!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type" ``` We've had this problem and solved it before; see #579.

2 files changed, 28 insertions(+), 17 deletions(-)

src/analyze.cpp+26-16
......@@ -7864,6 +7864,26 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
78647864 }
78657865}
78667866
7867// This is to be used instead of void for debug info types, to avoid tripping
7868// Assertion `!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type"'
7869// when targeting CodeView (Windows).
7870static ZigLLVMDIType *make_empty_namespace_llvm_di_type(CodeGen *g, ZigType *import, const char *name,
7871 AstNode *decl_node)
7872{
7873 uint64_t debug_size_in_bits = 0;
7874 uint64_t debug_align_in_bits = 0;
7875 ZigLLVMDIType **di_element_types = nullptr;
7876 size_t debug_field_count = 0;
7877 return ZigLLVMCreateDebugStructType(g->dbuilder,
7878 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
7879 name,
7880 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
7881 debug_size_in_bits,
7882 debug_align_in_bits,
7883 ZigLLVM_DIFlags_Zero,
7884 nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
7885}
7886
78677887static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatus wanted_resolve_status) {
78687888 assert(enum_type->data.enumeration.resolve_status >= ResolveStatusSizeKnown);
78697889 if (enum_type->data.enumeration.resolve_status >= wanted_resolve_status) return;
......@@ -7874,19 +7894,8 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu
78747894
78757895 if (!type_has_bits(enum_type)) {
78767896 enum_type->llvm_type = g->builtin_types.entry_void->llvm_type;
7877
7878 uint64_t debug_size_in_bits = 0;
7879 uint64_t debug_align_in_bits = 0;
7880 ZigLLVMDIType **di_element_types = nullptr;
7881 size_t debug_field_count = 0;
7882 enum_type->llvm_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
7883 ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
7884 buf_ptr(&enum_type->name),
7885 import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
7886 debug_size_in_bits,
7887 debug_align_in_bits,
7888 ZigLLVM_DIFlags_Zero,
7889 nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
7897 enum_type->llvm_di_type = make_empty_namespace_llvm_di_type(g, import, buf_ptr(&enum_type->name),
7898 decl_node);
78907899 enum_type->data.enumeration.resolve_status = ResolveStatusLLVMFull;
78917900 return;
78927901 }
......@@ -7927,6 +7936,8 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
79277936 if (union_type->data.unionation.resolve_status >= wanted_resolve_status) return;
79287937
79297938 bool packed = (union_type->data.unionation.layout == ContainerLayoutPacked);
7939 Scope *scope = &union_type->data.unionation.decls_scope->base;
7940 ZigType *import = get_scope_import(scope);
79307941
79317942 TypeUnionField *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
79327943 ZigType *tag_type = union_type->data.unionation.tag_type;
......@@ -7934,7 +7945,8 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
79347945 if (gen_field_count == 0) {
79357946 if (tag_type == nullptr) {
79367947 union_type->llvm_type = g->builtin_types.entry_void->llvm_type;
7937 union_type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
7948 union_type->llvm_di_type = make_empty_namespace_llvm_di_type(g, import, buf_ptr(&union_type->name),
7949 union_type->data.unionation.decl_node);
79387950 } else {
79397951 union_type->llvm_type = get_llvm_type(g, tag_type);
79407952 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);
......@@ -7943,8 +7955,6 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
79437955 return;
79447956 }
79457957
7946 Scope *scope = &union_type->data.unionation.decls_scope->base;
7947 ZigType *import = get_scope_import(scope);
79487958 AstNode *decl_node = union_type->data.unionation.decl_node;
79497959
79507960 if (union_type->data.unionation.resolve_status < ResolveStatusLLVMFwdDecl) {
test/stage1/behavior/union.zig+2-1
......@@ -1,4 +1,5 @@
1const expect = @import("std").testing.expect;
1const std = @import("std");
2const expect = std.testing.expect;
23
34const Value = union(enum) {
45 Int: u64,