From 9d66481e3df35b54275373a685e765a4bcebd712 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Fri, 23 Jun 2023 13:36:32 -0400 Subject: [PATCH] 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). --- src/codegen/llvm.zig | 2 +- src/codegen/llvm/bindings.zig | 2 +- src/zig_llvm.cpp | 2 +- src/zig_llvm.h | 2 +- test/cases/llvm/large_slices.zig | 9 +++++++++ 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 test/cases/llvm/large_slices.zig diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 2a48ed0eb2159ad70a518d40391361d33a2287d2..78f8d2879710bde15b6b9b7f6c5b9a2366dc6b6d 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1719,7 +1719,7 @@ pub const Object = struct { ty.abiSize(mod) * 8, ty.abiAlignment(mod) * 8, try o.lowerDebugType(ty.childType(mod), .full), - @intCast(c_int, ty.arrayLen(mod)), + @intCast(i64, ty.arrayLen(mod)), ); // The recursive call to `lowerDebugType` means we can't use `gop` anymore. try o.di_type_map.put(gpa, ty.toIntern(), AnnotatedDITypePtr.initFull(array_di_ty)); diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig index 758cf5c72188ead9efed8cc125e8408b4f3bcac2..a8249a870fad04a8d4e6dd6ceb6fafbca45f3743 100644 --- a/src/codegen/llvm/bindings.zig +++ b/src/codegen/llvm/bindings.zig @@ -1681,7 +1681,7 @@ pub const DIBuilder = opaque { size_in_bits: u64, align_in_bits: u64, elem_type: *DIType, - elem_count: c_int, + elem_count: i64, ) *DIType; pub const createEnumerator = ZigLLVMCreateDebugEnumerator; diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index af53bd1d27a2b8870b730be767730465fee055e3..b04356bf4de6abd4925dbe583c14daee7c372e5d 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -601,7 +601,7 @@ struct ZigLLVMDIType *ZigLLVMDIBuilderCreateVectorType(struct ZigLLVMDIBuilder * } ZigLLVMDIType *ZigLLVMCreateDebugArrayType(ZigLLVMDIBuilder *dibuilder, uint64_t size_in_bits, - uint64_t align_in_bits, ZigLLVMDIType *elem_type, int elem_count) + uint64_t align_in_bits, ZigLLVMDIType *elem_type, int64_t elem_count) { SmallVector subrange; subrange.push_back(reinterpret_cast(dibuilder)->getOrCreateSubrange(0, elem_count)); diff --git a/src/zig_llvm.h b/src/zig_llvm.h index 8f24d045a2b8b62564051b54d0834d5098159ad8..74dcd105649ab9633f67a8caaf26e2d3ba5b5aef 100644 --- a/src/zig_llvm.h +++ b/src/zig_llvm.h @@ -179,7 +179,7 @@ ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugBasicType(struct ZigLLVMDIB ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugArrayType(struct ZigLLVMDIBuilder *dibuilder, uint64_t size_in_bits, uint64_t align_in_bits, struct ZigLLVMDIType *elem_type, - int elem_count); + int64_t elem_count); ZIG_EXTERN_C struct ZigLLVMDIEnumerator *ZigLLVMCreateDebugEnumerator(struct ZigLLVMDIBuilder *dibuilder, const char *name, uint64_t val, bool isUnsigned); diff --git a/test/cases/llvm/large_slices.zig b/test/cases/llvm/large_slices.zig new file mode 100644 index 0000000000000000000000000000000000000000..f90e588ab0a1f8441f2c5ffea887880b202ebf1c --- /dev/null +++ b/test/cases/llvm/large_slices.zig @@ -0,0 +1,9 @@ +pub fn main() void { + const large_slice = @ptrFromInt([*]const u8, 1)[0..(0xffffffffffffffff >> 3)]; + _ = large_slice; +} + +// compile +// backend=llvm +// target=x86_64-linux,x86_64-macos +// -- 2.54.0