Skip to content

Commit 7700e6c

Browse files
committed
[AMDGPU][LowerModuleLDS] Avoid crash on zero-sized types
1 parent 5e379b6 commit 7700e6c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,10 @@ class AMDGPULowerModuleLDS {
13981398
LDSVarsToTransform.begin(), LDSVarsToTransform.end()));
13991399

14001400
for (GlobalVariable *GV : Sorted) {
1401+
if (DL.getTypeAllocSize(GV->getValueType()) == 0)
1402+
report_fatal_error("cannot lower LDS '" + GV->getName() +
1403+
"' because it has a zero-sized type");
1404+
14011405
OptimizedStructLayoutField F(GV,
14021406
DL.getTypeAllocSize(GV->getValueType()),
14031407
AMDGPU::getAlign(DL, GV));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: not --crash opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s 2>&1 | FileCheck %s
2+
; RUN: not --crash opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s 2>&1 | FileCheck %s
3+
4+
; CHECK: LLVM ERROR: cannot lower LDS 'var0' because it has a zero-sized type
5+
@var0 = internal addrspace(3) global [0 x float] poison, align 4
6+
7+
define amdgpu_kernel void @kernel() {
8+
load float, ptr addrspace(3) @var0
9+
ret void
10+
}

0 commit comments

Comments
 (0)