Skip to content

Conversation

@jmmartinez
Copy link
Contributor

This patch doesn't change anything. Just adds more explicit checks to verify what is generated in this case when an alloca has a zero-sized array.

I was expecting an OpRuntimeArray but nothing is generated.

@jmmartinez jmmartinez self-assigned this Nov 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2025

@llvm/pr-subscribers-backend-spir-v

Author: Juan Manuel Martinez Caamaño (jmmartinez)

Changes

This patch doesn't change anything. Just adds more explicit checks to verify what is generated in this case when an alloca has a zero-sized array.

I was expecting an OpRuntimeArray but nothing is generated.


Full diff: https://github.com/llvm/llvm-project/pull/166910.diff

1 Files Affected:

  • (modified) llvm/test/CodeGen/SPIRV/zero-length-array.ll (+10-3)
diff --git a/llvm/test/CodeGen/SPIRV/zero-length-array.ll b/llvm/test/CodeGen/SPIRV/zero-length-array.ll
index 666176c87adb6..9cb4775785988 100644
--- a/llvm/test/CodeGen/SPIRV/zero-length-array.ll
+++ b/llvm/test/CodeGen/SPIRV/zero-length-array.ll
@@ -1,10 +1,17 @@
 ; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - | FileCheck %s
 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
 
-; CHECK: %[[#type:]] = OpTypeInt 32 0
-; CHECK: %[[#ext:]] = OpConstant %[[#type]] 0
+; Nothing is generated, but compilation doesn't crash
+; CHECK: OpName %[[#FOO:]] "foo"
+; CHECK: OpName %[[#RTM:]] "reg2mem alloca point"
+; CHECK: %[[#INT:]] = OpTypeInt 32 0
+; CHECK: %[[#RTM]] = OpConstant %[[#INT]] 0
+; CHECK: %[[#FOO]] = OpFunction
+; CHECK-NEXT: = OpLabel
+; CHECK-NEXT: OpReturn
+; CHECK-NEXT: OpFunctionEnd
 
-define spir_func void @_Z3foov() {
+define spir_func void @foo() {
 entry:
   %i = alloca [0 x i32], align 4
   ret void

Co-authored-by: Marcos Maronas <[email protected]>
@jmmartinez jmmartinez enabled auto-merge (squash) November 10, 2025 08:11
@jmmartinez jmmartinez merged commit d0081aa into main Nov 10, 2025
8 of 10 checks passed
@jmmartinez jmmartinez deleted the users/jmmartinez/spirv/explicit_zero-length_array branch November 10, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants