[PATCH] D147854: [NVPTX] Fix integer overflow for alloca arrays
Alex MacLean via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 8 10:53:15 PDT 2023
AlexM created this revision.
AlexM added a reviewer: tra.
Herald added subscribers: mattd, gchakrabarti, asavonic, hiraditya.
Herald added a project: All.
AlexM added a reviewer: yaxunl.
AlexM published this revision for review.
Herald added subscribers: llvm-commits, jholewinski.
Herald added a project: LLVM.
Similar to D146767 <https://reviews.llvm.org/D146767>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147854
Files:
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/test/CodeGen/NVPTX/local-variable-big.ll
Index: llvm/test/CodeGen/NVPTX/local-variable-big.ll
===================================================================
--- /dev/null
+++ 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)
Index: llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ 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";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147854.511908.patch
Type: text/x-patch
Size: 1381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230408/8caf6dd2/attachment.bin>
More information about the llvm-commits
mailing list