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:02:00-04:00
log5e34fb35972b8ff2ec0a420779b689229d05c659
tree98e2236ab00fc527d1b46b815dec585c01bb3502
parentc4416b224d29692556d828c0902f6416f3f5b534
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...@@ -7864,6 +7864,26 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
7864 }7864 }
7865}7865}
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
7867static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatus wanted_resolve_status) {7887static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatus wanted_resolve_status) {
7868 assert(enum_type->data.enumeration.resolve_status >= ResolveStatusSizeKnown);7888 assert(enum_type->data.enumeration.resolve_status >= ResolveStatusSizeKnown);
7869 if (enum_type->data.enumeration.resolve_status >= wanted_resolve_status) return;7889 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...@@ -7874,19 +7894,8 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu
78747894
7875 if (!type_has_bits(enum_type)) {7895 if (!type_has_bits(enum_type)) {
7876 enum_type->llvm_type = g->builtin_types.entry_void->llvm_type;7896 enum_type->llvm_type = g->builtin_types.entry_void->llvm_type;
78777897 enum_type->llvm_di_type = make_empty_namespace_llvm_di_type(g, import, buf_ptr(&enum_type->name),
7878 uint64_t debug_size_in_bits = 0;7898 decl_node);
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, "");
7890 enum_type->data.enumeration.resolve_status = ResolveStatusLLVMFull;7899 enum_type->data.enumeration.resolve_status = ResolveStatusLLVMFull;
7891 return;7900 return;
7892 }7901 }
...@@ -7927,6 +7936,8 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta...@@ -7927,6 +7936,8 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
7927 if (union_type->data.unionation.resolve_status >= wanted_resolve_status) return;7936 if (union_type->data.unionation.resolve_status >= wanted_resolve_status) return;
79287937
7929 bool packed = (union_type->data.unionation.layout == ContainerLayoutPacked);7938 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
7931 TypeUnionField *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;7942 TypeUnionField *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
7932 ZigType *tag_type = union_type->data.unionation.tag_type;7943 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...@@ -7934,7 +7945,8 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
7934 if (gen_field_count == 0) {7945 if (gen_field_count == 0) {
7935 if (tag_type == nullptr) {7946 if (tag_type == nullptr) {
7936 union_type->llvm_type = g->builtin_types.entry_void->llvm_type;7947 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);
7938 } else {7950 } else {
7939 union_type->llvm_type = get_llvm_type(g, tag_type);7951 union_type->llvm_type = get_llvm_type(g, tag_type);
7940 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);7952 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...@@ -7943,8 +7955,6 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
7943 return;7955 return;
7944 }7956 }
79457957
7946 Scope *scope = &union_type->data.unionation.decls_scope->base;
7947 ZigType *import = get_scope_import(scope);
7948 AstNode *decl_node = union_type->data.unionation.decl_node;7958 AstNode *decl_node = union_type->data.unionation.decl_node;
79497959
7950 if (union_type->data.unionation.resolve_status < ResolveStatusLLVMFwdDecl) {7960 if (union_type->data.unionation.resolve_status < ResolveStatusLLVMFwdDecl) {
test/stage1/behavior/union.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const expect = @import("std").testing.expect;1const std = @import("std");
2const expect = std.testing.expect;
23
3const Value = union(enum) {4const Value = union(enum) {
4 Int: u64,5 Int: u64,