Skip to content

Commit 6a423ee

Browse files
committed
[NVPTX] Fix integer overflow affecting array size calculation.
It turns out, 4GB+ large arrays are a thing and a 32-bit integer is just not enough to handle them. Differential Revision: https://reviews.llvm.org/D146767
1 parent f23ea4c commit 6a423ee

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
11481148
}
11491149
}
11501150
} else {
1151-
unsigned int ElementSize = 0;
1151+
uint64_t ElementSize = 0;
11521152

11531153
// Although PTX has direct support for struct type and array type and
11541154
// LLVM IR is very similar to PTX, the LLVM CodeGen does not support for

llvm/test/CodeGen/NVPTX/global-variable-big.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ target triple = "nvptx64-nvidia-cuda"
99
; (lsb) 0x0102'0304'0506...0F10 (msb)
1010
@gv = addrspace(1) externally_initialized global i128 21345817372864405881847059188222722561, align 16
1111
; CHECK: .visible .global .align 16 .b8 gv[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
12+
13+
; Make sure that we do not overflow on large number of elements.
14+
; CHECK-LABEL large_data
15+
; CHECK: .visible .global .align 1 .b8 large_data[4831838208]
16+
@large_data = global [4831838208 x i8] zeroinitializer
17+
18+

0 commit comments

Comments
 (0)