Skip to content

Commit

Permalink
[NVPTX] Fix integer overflow affecting array size calculation.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Artem-B committed Mar 24, 2023
1 parent f23ea4c commit 6a423ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
Expand Up @@ -1148,7 +1148,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
}
}
} else {
unsigned int ElementSize = 0;
uint64_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
Expand Down
7 changes: 7 additions & 0 deletions llvm/test/CodeGen/NVPTX/global-variable-big.ll
Expand Up @@ -9,3 +9,10 @@ target triple = "nvptx64-nvidia-cuda"
; (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]
@large_data = global [4831838208 x i8] zeroinitializer


0 comments on commit 6a423ee

Please sign in to comment.