Skip to content

Commit 7c4cc9e

Browse files
committed
[SPIRV] Error for zero-length arrays if not a shader
Signed-off-by: Nick Sarnie <[email protected]>
1 parent c378bb1 commit 7c4cc9e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,15 @@ 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())
889-
return nullptr;
886+
if (!ST.isShader()) {
887+
Function &Fn = MIRBuilder.getMF().getFunction();
888+
Fn.getContext().diagnose(DiagnosticInfoUnsupported(
889+
Fn,
890+
"Runtime arrays are not allowed in non-shader "
891+
"SPIR-V modules",
892+
MIRBuilder.getDebugLoc()));
893+
return ElemType;
894+
}
890895
ArrayType = createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
891896
return MIRBuilder.buildInstr(SPIRV::OpTypeRuntimeArray)
892897
.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: in function foo void (): 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)