KhronosGroup / KhronosGroup/glslang
glsl: fails to reject shaders that use array-of-void
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
Glslang compiles this to SPIR-V.
```glsl
#version 320 es
void[2] foo() { }
void main() { foo(); }
```
The GLSL ES 3.2 spec [says](https://registry.khronos.org/OpenGL/specs/es/3.2/GLSL_ES_Specification_3.20.html#basic-types:~:text=The%20keyword%20void%20cannot%20be%20used%20in%20any%20other%20declarations%20(except%20for%20empty%20formal%20or%20actual%20parameter%20lists)%2C%20or%20an%20error%20results.):
> Functions that do not return a value must be declared as *void*. There is no default function return type. The keyword *void* cannot be used in any other declarations (except for empty formal or actual parameter lists), or an error results.
**Glslang should fail compilation of the shader, and emit an error.**
(In the generated spir-v foo returns an OpUndef of type array-of-two-void)
Glslang (correctly) rejects this shader:
```glsl
void[2] bar() { }
void[2] foo() { return bar(); }
void main() { foo(); }
```
producing this error:
```
b.comp
ERROR: b.comp:3: 'return' : void function cannot return a value
ERROR: b.comp:3: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.
```
The error is not quite right, because it implies `foo` is a 'void function'. That quality of the message was quite secondary.
This is super low priority for me. I was just messing around. :-)
Contributor guide
Research direction
Run the provided GLSL ES 3.2 shader through glslang and compare it with the second example that is already rejected. Trace the compiler's validation of function return types and array-of-void declarations. Done means the first shader emits a compilation error instead of producing SPIR-V, while the existing rejection remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100