[llvm] [SPIRV] Do not use OpTypeRuntimeArray in Kernel env. (PR #149522)
Victor Lomuller via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 07:39:42 PDT 2025
================
@@ -828,9 +828,11 @@ SPIRVType *SPIRVGlobalRegistry::getOpTypeArray(uint32_t NumElems,
"Invalid array element type");
SPIRVType *SpvTypeInt32 = getOrCreateSPIRVIntegerType(32, MIRBuilder);
SPIRVType *ArrayType = nullptr;
- if (NumElems != 0) {
- Register NumElementsVReg =
- buildConstantInt(NumElems, MIRBuilder, SpvTypeInt32, EmitIR);
+ const SPIRVSubtarget &ST =
+ cast<SPIRVSubtarget>(MIRBuilder.getMF().getSubtarget());
+ if (NumElems != 0 || !ST.isShader()) {
+ Register NumElementsVReg = buildConstantInt(
+ NumElems ? NumElems : 1, MIRBuilder, SpvTypeInt32, EmitIR);
----------------
Naghasan wrote:
> But examples like https://godbolt.org/z/zaTT7nTvr are already UB
This isn't UB at all, it is outside the core specs (C++ says 0 is not valid) but it is a valid compiler extension (add `-pedantic` and you get a `warning: zero size arrays are an extension [-Wzero-length-array]`). And `0` as first offset makes it perfectly fine as well (you don't move the pointer). And in other languages, there is valid reasons to have this construct.
> BTW, @Naghasan do you happen to know, why OpTypeRuntimeArray is not allowed for Kernel? It's not looking like VLA to me.
This isn't linked to VLA, but a Vulkan runtime construct that isn't mappable in OpenCL
https://github.com/llvm/llvm-project/pull/149522
More information about the llvm-commits
mailing list