diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-12-18 06:50:48 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-18 06:50:48 -0500 |
| commit | f24c77fc48b7272618b48cac7bb15d6997e95c5a (patch) | |
| tree | cc75a53ed2774ae1556f0f0d5a16c2b60b9eb32a /src | |
| parent | 4809e0ea7f53d1b56cbc4c6e62e4b8ea40936d44 (diff) | |
| parent | e0bc5f65b98d154b4318027d56f780b55605e33c (diff) | |
| download | zig-f24c77fc48b7272618b48cac7bb15d6997e95c5a.tar.gz zig-f24c77fc48b7272618b48cac7bb15d6997e95c5a.zip | |
Merge pull request #13992 from jacobly0/llvm-zwf
llvm: fix null pointer use when lowering pointer to final zero-width field of a comptime value
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen/llvm.zig | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index cd9ef98e44..68d929c5a4 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()); |
