SPIR-V validation error "OpVariable Initializer is not a constant or module-scope variable."
- Dominant language
- LLVM
- Stars
- 1.5k
- Forks
- 854
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 137
Description
Multiple SyCL CTS tests are triggering the "OpVariable Initializer is not a constant or module-scope variable." spir-v validation error, e.g. `test_h_item`
```
; SPIR-V
; Version: 1.4
; Generator: Khronos LLVM/SPIR-V Translator; 14
; Bound: 2018
; Schema: 0
...
%29 = OpUndef %class_sycl___V1__range_12
%WGCopy_4 = OpVariable %_ptr_Workgroup_class_sycl___V1__range_12 Workgroup %29
```
From the SPIR-V specification on [OpVariable](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpVariable):
"Initializer is optional. If Initializer is present, it will be the initial value of the variable’s memory content. Initializer must be an from a [constant instruction](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#ConstantInstruction) or a global (module scope) [OpVariable](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpVariable) instruction. Initializer must have the same type as the type pointed to by Result Type."
further on [constant instruction](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#ConstantInstruction) it states:
"Constant Instruction: Either a specialization-constant instruction or a non-specialization constant instruction: Instructions that start "OpConstant" or "OpSpec"."
Granted this could have been an oversight when adding this in [SPIR-V 1.5 Revision 2](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_changes_from_version_1_5_revision_2):
"Khronos Issue #550: Include OpUndef in the allowed constituents for [OpSpecConstantComposite](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpSpecConstantComposite)."
But the generated SPIR-V is declared as version 1.4 and that exception wouldn't be able to apply even if fixed in the specification.
Contributor guide
Assessment
This issue has not been assessed yet.