authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-06-23 13:36:32-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-23 14:53:17-07:00
log9d66481e3df35b54275373a685e765a4bcebd712
tree7265504b2f0cddd12ea07eb68d5b6e8c3d12778a
parent8dcb4a3dc44fcc90b43543b9a0603456eeb4c348

llvm: fixup elem_count argument of ZigLLVMCreateDebugArrayType to be i64

The signature is `getOrCreateSubrange(int64_t Lo, int64_t Count)`, so this updates the bindings to match. This fixes a crash in `lowerDebugTypeImpl` when analyzing slices that have a length of 2^32 or larger (up to `2^64 >> 3`, which still crashes, because above that the array size in bits overflows u64).

5 files changed, 13 insertions(+), 4 deletions(-)

src/codegen/llvm.zig+1-1
......@@ -1719,7 +1719,7 @@ pub const Object = struct {
17191719 ty.abiSize(mod) * 8,
17201720 ty.abiAlignment(mod) * 8,
17211721 try o.lowerDebugType(ty.childType(mod), .full),
1722 @intCast(c_int, ty.arrayLen(mod)),
1722 @intCast(i64, ty.arrayLen(mod)),
17231723 );
17241724 // The recursive call to `lowerDebugType` means we can't use `gop` anymore.
17251725 try o.di_type_map.put(gpa, ty.toIntern(), AnnotatedDITypePtr.initFull(array_di_ty));
src/codegen/llvm/bindings.zig+1-1
......@@ -1681,7 +1681,7 @@ pub const DIBuilder = opaque {
16811681 size_in_bits: u64,
16821682 align_in_bits: u64,
16831683 elem_type: *DIType,
1684 elem_count: c_int,
1684 elem_count: i64,
16851685 ) *DIType;
16861686
16871687 pub const createEnumerator = ZigLLVMCreateDebugEnumerator;
src/zig_llvm.cpp+1-1
......@@ -601,7 +601,7 @@ struct ZigLLVMDIType *ZigLLVMDIBuilderCreateVectorType(struct ZigLLVMDIBuilder *
601601}
602602
603603ZigLLVMDIType *ZigLLVMCreateDebugArrayType(ZigLLVMDIBuilder *dibuilder, uint64_t size_in_bits,
604 uint64_t align_in_bits, ZigLLVMDIType *elem_type, int elem_count)
604 uint64_t align_in_bits, ZigLLVMDIType *elem_type, int64_t elem_count)
605605{
606606 SmallVector<Metadata *, 1> subrange;
607607 subrange.push_back(reinterpret_cast<DIBuilder*>(dibuilder)->getOrCreateSubrange(0, elem_count));
src/zig_llvm.h+1-1
......@@ -179,7 +179,7 @@ ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugBasicType(struct ZigLLVMDIB
179179
180180ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugArrayType(struct ZigLLVMDIBuilder *dibuilder,
181181 uint64_t size_in_bits, uint64_t align_in_bits, struct ZigLLVMDIType *elem_type,
182 int elem_count);
182 int64_t elem_count);
183183
184184ZIG_EXTERN_C struct ZigLLVMDIEnumerator *ZigLLVMCreateDebugEnumerator(struct ZigLLVMDIBuilder *dibuilder,
185185 const char *name, uint64_t val, bool isUnsigned);
test/cases/llvm/large_slices.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 const large_slice = @ptrFromInt([*]const u8, 1)[0..(0xffffffffffffffff >> 3)];
3 _ = large_slice;
4}
5
6// compile
7// backend=llvm
8// target=x86_64-linux,x86_64-macos
9//