aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2025-08-13 23:55:21 +0100
committerGitHub <noreply@github.com>2025-08-13 23:55:21 +0100
commitb87b9586878a95c281bf76c4cefc75a9a81f1865 (patch)
tree7f66d8dc37f9590b390e1df7f4647f6247d83eea /src/codegen
parent3736aac77868b867e0d529a3c393069537836451 (diff)
parentba6abd71c2d3664bc658cf5ce55b5c53052dc720 (diff)
downloadzig-b87b9586878a95c281bf76c4cefc75a9a81f1865.tar.gz
zig-b87b9586878a95c281bf76c4cefc75a9a81f1865.zip
Merge pull request #24816 from mlugg/small-fixes
two small fixes
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index d6313305ac..5c683a965a 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -10475,11 +10475,14 @@ pub const FuncGen = struct {
const slice_ty = self.typeOfIndex(inst);
const slice_llvm_ty = try o.lowerType(pt, slice_ty);
+ // If operand is small (e.g. `u8`), then signedness becomes a problem -- GEP always treats the index as signed.
+ const extended_operand = try self.wip.conv(.unsigned, operand, try o.lowerType(pt, .usize), "");
+
const error_name_table_ptr = try self.getErrorNameTable();
const error_name_table =
try self.wip.load(.normal, .ptr, error_name_table_ptr.toValue(&o.builder), .default, "");
const error_name_ptr =
- try self.wip.gep(.inbounds, slice_llvm_ty, error_name_table, &.{operand}, "");
+ try self.wip.gep(.inbounds, slice_llvm_ty, error_name_table, &.{extended_operand}, "");
return self.wip.load(.normal, slice_llvm_ty, error_name_ptr, .default, "");
}
@@ -12774,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);