diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index bccb67ec3c..1aa8e86a7f 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -12777,7 +12777,7 @@ fn isByRef(ty: Type, zcu: *Zcu) bool { }, .@"union" => switch (ty.containerLayout(zcu)) { .@"packed" => return false, - else => return ty.hasRuntimeBits(zcu), + else => return ty.hasRuntimeBits(zcu) and !ty.unionHasAllZeroBitFieldTypes(zcu), }, .error_union => { const payload_ty = ty.errorUnionPayload(zcu); diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index 740d123170..7eee20e3e0 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -2722,3 +2722,18 @@ test "@intFromFloat vector boundary cases" { try S.doTheTest(); try comptime S.doTheTest(); } + +test "coerce enum to union with zero-bit fields through local variables" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + + const E = enum(u1) { foo, bar }; + const U = union(E) { foo, bar }; + + var runtime: E = undefined; + runtime = .foo; + + var result: U = undefined; + result = runtime; + + try expect(result == .foo); +}