authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-08-13 23:55:21+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-08-13 23:55:21+01:00
logb87b9586878a95c281bf76c4cefc75a9a81f1865
tree7f66d8dc37f9590b390e1df7f4647f6247d83eea
parent3736aac77868b867e0d529a3c393069537836451
parentba6abd71c2d3664bc658cf5ce55b5c53052dc720
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #24816 from mlugg/small-fixes

two small fixes

2 files changed, 20 insertions(+), 2 deletions(-)

src/codegen/llvm.zig+5-2
...@@ -10475,11 +10475,14 @@ pub const FuncGen = struct {...@@ -10475,11 +10475,14 @@ pub const FuncGen = struct {
10475 const slice_ty = self.typeOfIndex(inst);10475 const slice_ty = self.typeOfIndex(inst);
10476 const slice_llvm_ty = try o.lowerType(pt, slice_ty);10476 const slice_llvm_ty = try o.lowerType(pt, slice_ty);
1047710477
10478 // If operand is small (e.g. `u8`), then signedness becomes a problem -- GEP always treats the index as signed.
10479 const extended_operand = try self.wip.conv(.unsigned, operand, try o.lowerType(pt, .usize), "");
10480
10478 const error_name_table_ptr = try self.getErrorNameTable();10481 const error_name_table_ptr = try self.getErrorNameTable();
10479 const error_name_table =10482 const error_name_table =
10480 try self.wip.load(.normal, .ptr, error_name_table_ptr.toValue(&o.builder), .default, "");10483 try self.wip.load(.normal, .ptr, error_name_table_ptr.toValue(&o.builder), .default, "");
10481 const error_name_ptr =10484 const error_name_ptr =
10482 try self.wip.gep(.inbounds, slice_llvm_ty, error_name_table, &.{operand}, "");10485 try self.wip.gep(.inbounds, slice_llvm_ty, error_name_table, &.{extended_operand}, "");
10483 return self.wip.load(.normal, slice_llvm_ty, error_name_ptr, .default, "");10486 return self.wip.load(.normal, slice_llvm_ty, error_name_ptr, .default, "");
10484 }10487 }
1048510488
...@@ -12774,7 +12777,7 @@ fn isByRef(ty: Type, zcu: *Zcu) bool {...@@ -12774,7 +12777,7 @@ fn isByRef(ty: Type, zcu: *Zcu) bool {
12774 },12777 },
12775 .@"union" => switch (ty.containerLayout(zcu)) {12778 .@"union" => switch (ty.containerLayout(zcu)) {
12776 .@"packed" => return false,12779 .@"packed" => return false,
12777 else => return ty.hasRuntimeBits(zcu),12780 else => return ty.hasRuntimeBits(zcu) and !ty.unionHasAllZeroBitFieldTypes(zcu),
12778 },12781 },
12779 .error_union => {12782 .error_union => {
12780 const payload_ty = ty.errorUnionPayload(zcu);12783 const payload_ty = ty.errorUnionPayload(zcu);
test/behavior/cast.zig+15
...@@ -2722,3 +2722,18 @@ test "@intFromFloat vector boundary cases" {...@@ -2722,3 +2722,18 @@ test "@intFromFloat vector boundary cases" {
2722 try S.doTheTest();2722 try S.doTheTest();
2723 try comptime S.doTheTest();2723 try comptime S.doTheTest();
2724}2724}
2725
2726test "coerce enum to union with zero-bit fields through local variables" {
2727 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
2728
2729 const E = enum(u1) { foo, bar };
2730 const U = union(E) { foo, bar };
2731
2732 var runtime: E = undefined;
2733 runtime = .foo;
2734
2735 var result: U = undefined;
2736 result = runtime;
2737
2738 try expect(result == .foo);
2739}