[PATCH] D146767: [NVPTX] Fix integer overflow affecting array size calculation.
Artem Belevich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 23 15:32:30 PDT 2023
tra created this revision.
Herald added subscribers: mattd, gchakrabarti, asavonic, bixia, hiraditya.
Herald added a project: All.
tra updated this revision to Diff 507901.
tra added a comment.
tra published this revision for review.
tra added a reviewer: yaxunl.
Herald added subscribers: llvm-commits, jholewinski.
Herald added a project: LLVM.
.
It turns out, 4GB+ large arrays are a thing and a 32-bit integer is just not
enough to handle them.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146767
Files:
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/test/CodeGen/NVPTX/global-variable-big.ll
Index: llvm/test/CodeGen/NVPTX/global-variable-big.ll
===================================================================
--- llvm/test/CodeGen/NVPTX/global-variable-big.ll
+++ llvm/test/CodeGen/NVPTX/global-variable-big.ll
@@ -9,3 +9,10 @@
; (lsb) 0x0102'0304'0506...0F10 (msb)
@gv = addrspace(1) externally_initialized global i128 21345817372864405881847059188222722561, align 16
; CHECK: .visible .global .align 16 .b8 gv[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+
+; Make sure that we do not overflow on large number of elements.
+; CHECK-LABEL large_data
+; CHECK: .visible .global .align 1 .b8 large_data[4831838208]
+ at large_data = global [4831838208 x i8] zeroinitializer
+
+
Index: llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -1148,7 +1148,7 @@
}
}
} else {
- unsigned int ElementSize = 0;
+ size_t ElementSize = 0;
// Although PTX has direct support for struct type and array type and
// LLVM IR is very similar to PTX, the LLVM CodeGen does not support for
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146767.507901.patch
Type: text/x-patch
Size: 1186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230323/2ec5460d/attachment.bin>
More information about the llvm-commits
mailing list