diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -1669,7 +1669,7 @@ // Emit the Fake Stack Object const MachineFrameInfo &MFI = MF.getFrameInfo(); - int NumBytes = (int) MFI.getStackSize(); + int64_t NumBytes = MFI.getStackSize(); if (NumBytes) { O << "\t.local .align " << MFI.getMaxAlign().value() << " .b8 \t" << DEPOTNAME << getFunctionNumber() << "[" << NumBytes << "];\n"; diff --git a/llvm/test/CodeGen/NVPTX/local-variable-big.ll b/llvm/test/CodeGen/NVPTX/local-variable-big.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/NVPTX/local-variable-big.ll @@ -0,0 +1,18 @@ +; RUN: llc < %s -march=nvptx | FileCheck %s +; RUN: llc < %s -march=nvptx64 | FileCheck %s +; RUN: %if ptxas %{ llc < %s -march=nvptx | %ptxas-verify %} +; RUN: %if ptxas %{ llc < %s -march=nvptx64 | %ptxas-verify %} + +; Make sure there is no integer overflow in the compiler when large +; local arrays are used. +; +; CHECK: .local .align 1 .b8 __local_depot0[4831838208]; +; +define i32 @large_data() { + %arr = alloca [4831838208 x i8] + %p = getelementptr inbounds [4831838208 x i8], [4831838208 x i8]* %arr, i64 0, i64 0 + %call = call i32 @use(ptr %p) + ret i32 %call +} + +declare i32 @use(ptr %p)