diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp index 0b89e5f4cf316..a69ab958baf38 100644 --- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp @@ -883,10 +883,12 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeArray(uint32_t NumElems, .addUse(NumElementsVReg); }); } else { - assert(ST.isShader() && "Runtime arrays are not allowed in non-shader " - "SPIR-V modules."); - if (!ST.isShader()) + if (!ST.isShader()) { + llvm::reportFatalUsageError( + "Runtime arrays are not allowed in non-shader " + "SPIR-V modules"); return nullptr; + } ArrayType = createOpType(MIRBuilder, [&](MachineIRBuilder &MIRBuilder) { return MIRBuilder.buildInstr(SPIRV::OpTypeRuntimeArray) .addDef(createTypeVReg(MIRBuilder)) diff --git a/llvm/test/CodeGen/SPIRV/zero-length-array.ll b/llvm/test/CodeGen/SPIRV/zero-length-array.ll index 5fd94d25dfd87..cb34529ebfecd 100644 --- a/llvm/test/CodeGen/SPIRV/zero-length-array.ll +++ b/llvm/test/CodeGen/SPIRV/zero-length-array.ll @@ -1,7 +1,9 @@ -; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - | FileCheck %s +; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan-compute < %s | FileCheck %s ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %} -; Nothing is generated, but compilation doesn't crash. +; RUN: not llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown < %s 2>&1 | FileCheck -check-prefix=CHECK-ERR %s + +; For compute, nothing is generated, but compilation doesn't crash. ; CHECK: OpName %[[#FOO:]] "foo" ; CHECK: OpName %[[#RTM:]] "reg2mem alloca point" ; CHECK: %[[#INT:]] = OpTypeInt 32 0 @@ -11,6 +13,10 @@ ; CHECK-NEXT: OpReturn ; CHECK-NEXT: OpFunctionEnd + +; For non-compute, error. +; CHECK-ERR: LLVM ERROR: Runtime arrays are not allowed in non-shader SPIR-V modules + define spir_func void @foo() { entry: %i = alloca [0 x i32], align 4