Skip to content

Commit 1a3709c

Browse files
authored
[SPIRV] Error for zero-length arrays if not a shader (#169732)
I had a case where the frontend was generating a zero elem array in non-shader code so it was just crashing in a release build. Add a real error and make it not crash. --------- Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
1 parent e0db7f3 commit 1a3709c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,12 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeArray(uint32_t NumElems,
883883
.addUse(NumElementsVReg);
884884
});
885885
} else {
886-
assert(ST.isShader() && "Runtime arrays are not allowed in non-shader "
887-
"SPIR-V modules.");
888-
if (!ST.isShader())
886+
if (!ST.isShader()) {
887+
llvm::reportFatalUsageError(
888+
"Runtime arrays are not allowed in non-shader "
889+
"SPIR-V modules");
889890
return nullptr;
891+
}
890892
ArrayType = createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
891893
return MIRBuilder.buildInstr(SPIRV::OpTypeRuntimeArray)
892894
.addDef(createTypeVReg(MIRBuilder))

llvm/test/CodeGen/SPIRV/zero-length-array.ll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - | FileCheck %s
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan-compute < %s | FileCheck %s
22
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
33

4-
; Nothing is generated, but compilation doesn't crash.
4+
; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown < %s 2>&1 | FileCheck -check-prefix=CHECK-ERR %s
5+
6+
; For compute, nothing is generated, but compilation doesn't crash.
57
; CHECK: OpName %[[#FOO:]] "foo"
68
; CHECK: OpName %[[#RTM:]] "reg2mem alloca point"
79
; CHECK: %[[#INT:]] = OpTypeInt 32 0
@@ -11,6 +13,10 @@
1113
; CHECK-NEXT: OpReturn
1214
; CHECK-NEXT: OpFunctionEnd
1315

16+
17+
; For non-compute, error.
18+
; CHECK-ERR: LLVM ERROR: Runtime arrays are not allowed in non-shader SPIR-V modules
19+
1420
define spir_func void @foo() {
1521
entry:
1622
%i = alloca [0 x i32], align 4

0 commit comments

Comments
 (0)