KhronosGroup / KhronosGroup/GLSL
Requirements for function `return` calls
- Dominant language
- JavaScript
- Stars
- 458
- Forks
- 114
- Avg merge
- 4m
- Merged PRs (30d)
- 1
Description
I can't find in the spec where it mentions when a function with a return value must call `return`. Playing around in godbot with glslang it appears that a single `return` is required but not all control paths must return, it injects an `undef` in those cases?
```glsl
int foo() {
}
```
Produces an error that the function must return a value.
```glsl
int foo() {
if (true) {
return 1;
}
}
```
Compiles correctly with the end of the function return an `OpUndef %int` value.
```glsl
int foo() {
if (true) {
return 1;
} else {
return 2;
}
}
```
Injects an `OpUnreachable` at the end of the function since all control paths return.
It seems like, there must be a single `return` call at any nesting level inside a function to be valid (according to glslang) and any other paths out of the function will return an `OpUndef` value.
Contributor guide
Research direction
Start with the GLSL specification sections covering function return values and control-flow completion, then compare them with the three glslang examples described in the issue. Document the required behavior and clarify whether the observed OpUndef and OpUnreachable results conform to the specification.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers, documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100