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 {
1047510475 const slice_ty = self.typeOfIndex(inst);
1047610476 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
1047810481 const error_name_table_ptr = try self.getErrorNameTable();
1047910482 const error_name_table =
1048010483 try self.wip.load(.normal, .ptr, error_name_table_ptr.toValue(&o.builder), .default, "");
1048110484 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}, "");
1048310486 return self.wip.load(.normal, slice_llvm_ty, error_name_ptr, .default, "");
1048410487 }
1048510488
......@@ -12774,7 +12777,7 @@ fn isByRef(ty: Type, zcu: *Zcu) bool {
1277412777 },
1277512778 .@"union" => switch (ty.containerLayout(zcu)) {
1277612779 .@"packed" => return false,
12777 else => return ty.hasRuntimeBits(zcu),
12780 else => return ty.hasRuntimeBits(zcu) and !ty.unionHasAllZeroBitFieldTypes(zcu),
1277812781 },
1277912782 .error_union => {
1278012783 const payload_ty = ty.errorUnionPayload(zcu);
test/behavior/cast.zig+15
......@@ -2722,3 +2722,18 @@ test "@intFromFloat vector boundary cases" {
27222722 try S.doTheTest();
27232723 try comptime S.doTheTest();
27242724}
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}