aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-11-16 01:11:12 +0200
committerVeikka Tuominen <git@vexu.eu>2022-11-16 01:13:35 +0200
commit28cbe5e92a36c81177dbcd2f33fc792468c08304 (patch)
tree4c75818b2b300ece49cc43947f7b850dfb483007 /src
parentfe6249348f615c975a2db53bb0c93f83bd2a281b (diff)
downloadzig-28cbe5e92a36c81177dbcd2f33fc792468c08304.tar.gz
zig-28cbe5e92a36c81177dbcd2f33fc792468c08304.zip
Sema+llvm: improve handling of namespace-like unions
Closes #13557
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig5
-rw-r--r--src/codegen/llvm.zig4
2 files changed, 4 insertions, 5 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 454722728b..64b4bf97db 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -22476,13 +22476,12 @@ fn fieldVal(
);
},
.Union => {
- const union_ty = try sema.resolveTypeFields(child_type);
-
- if (union_ty.getNamespace()) |namespace| {
+ if (child_type.getNamespace()) |namespace| {
if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| {
return inst;
}
}
+ const union_ty = try sema.resolveTypeFields(child_type);
if (union_ty.unionTagType()) |enum_ty| {
if (enum_ty.enumFieldIndex(field_name)) |field_index_usize| {
const field_index = @intCast(u32, field_index_usize);
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 763dde170b..af9dcacf48 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -2137,7 +2137,8 @@ pub const Object = struct {
break :blk fwd_decl;
};
- if (!ty.hasRuntimeBitsIgnoreComptime()) {
+ const union_obj = ty.cast(Type.Payload.Union).?.data;
+ if (!union_obj.haveFieldTypes() or !ty.hasRuntimeBitsIgnoreComptime()) {
const union_di_ty = try o.makeEmptyNamespaceDIType(owner_decl_index);
dib.replaceTemporary(fwd_decl, union_di_ty);
// The recursive call to `lowerDebugType` via `makeEmptyNamespaceDIType`
@@ -2147,7 +2148,6 @@ pub const Object = struct {
}
const layout = ty.unionGetLayout(target);
- const union_obj = ty.cast(Type.Payload.Union).?.data;
if (layout.payload_size == 0) {
const tag_di_ty = try o.lowerDebugType(union_obj.tag_ty, .full);