aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2022-12-18 01:25:19 -0500
committerJacob Young <jacobly0@users.noreply.github.com>2022-12-18 22:11:26 -0500
commite96f65db7735ef80e19253ec25a1ce31751650f1 (patch)
tree3356db8e593d43749b7ed2278ea1687428146ff8 /src/codegen/llvm.zig
parentaca9c74e80e106309b9783ff251ab0cdd3fb9626 (diff)
downloadzig-e96f65db7735ef80e19253ec25a1ce31751650f1.tar.gz
zig-e96f65db7735ef80e19253ec25a1ce31751650f1.zip
llvm: fix lowering pointer to final zero-width field of a comptime value
* Handle a `null` return from `llvmFieldIndex`. * Add a behavior test to test this code path. * Reword this test name, which incorrectly described how pointers to zero-bit fields behave, and instead describe the actual test.
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 7af987f4d6..39c797e12e 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -4033,16 +4033,24 @@ pub const DeclGen = struct {
const final_llvm_ty = (try dg.lowerType(ptr_child_ty)).pointerType(0);
break :blk field_addr.constIntToPtr(final_llvm_ty);
}
- bitcast_needed = !field_ty.eql(ptr_child_ty, dg.module);
var ty_buf: Type.Payload.Pointer = undefined;
- const llvm_field_index = llvmFieldIndex(parent_ty, field_index, target, &ty_buf).?;
- const indices: [2]*llvm.Value = .{
- llvm_u32.constInt(0, .False),
- llvm_u32.constInt(llvm_field_index, .False),
- };
+
const parent_llvm_ty = try dg.lowerType(parent_ty);
- break :blk parent_llvm_ty.constInBoundsGEP(parent_llvm_ptr, &indices, indices.len);
+ if (llvmFieldIndex(parent_ty, field_index, target, &ty_buf)) |llvm_field_index| {
+ bitcast_needed = !field_ty.eql(ptr_child_ty, dg.module);
+ const indices: [2]*llvm.Value = .{
+ llvm_u32.constInt(0, .False),
+ llvm_u32.constInt(llvm_field_index, .False),
+ };
+ break :blk parent_llvm_ty.constInBoundsGEP(parent_llvm_ptr, &indices, indices.len);
+ } else {
+ bitcast_needed = !parent_ty.eql(ptr_child_ty, dg.module);
+ const indices: [1]*llvm.Value = .{
+ llvm_u32.constInt(1, .False),
+ };
+ break :blk parent_llvm_ty.constInBoundsGEP(parent_llvm_ptr, &indices, indices.len);
+ }
},
.Pointer => {
assert(parent_ty.isSlice());