From 294f51814f491ae4a09348d9e7221ae3e550c16f Mon Sep 17 00:00:00 2001 From: Anton Lilja <12533691+antlilja@users.noreply.github.com> Date: Sun, 17 Mar 2024 12:25:09 +0100 Subject: [PATCH] LLVM lowerDebugType: Lower union types without a layout into an empty namespace --- src/codegen/llvm.zig | 5 ++++- test/cases/union_unresolved_layout.zig | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/cases/union_unresolved_layout.zig diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 2a5a187e0d..6273ce0942 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2598,7 +2598,10 @@ pub const Object = struct { defer gpa.free(name); const union_type = ip.loadUnionType(ty.toIntern()); - if (!union_type.haveFieldTypes(ip) or !ty.hasRuntimeBitsIgnoreComptime(mod)) { + if (!union_type.haveFieldTypes(ip) or + !ty.hasRuntimeBitsIgnoreComptime(mod) or + !union_type.haveLayout(ip)) + { const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); try o.debug_type_map.put(gpa, ty, debug_union_type); return debug_union_type; diff --git a/test/cases/union_unresolved_layout.zig b/test/cases/union_unresolved_layout.zig new file mode 100644 index 0000000000..f76c929e8a --- /dev/null +++ b/test/cases/union_unresolved_layout.zig @@ -0,0 +1,15 @@ +const std = @import("std"); + +const U = union(enum) { + foo: u8, + bar: f64, +}; + +pub fn main() !void { + const t = U.foo; + _ = t; +} + +// run +// backend=llvm +//