KhronosGroup / KhronosGroup/glslang
error in combination with preprocessor directives can obfuscate error location.
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
I'd like to address an issue with error handeling specifically in combination with common preprocessor directives like #include #line. I'll give you a short summary of the problem and how these system interact, and the situation of the problem.
```
layout( location = 0 ) out vec4 color1
#line 500
layout( location = 0 ) out vec4 color2:
```
Results in an "ERROR: frag.glsl:500: unexpected LAYOUT, expecting COMMA or SEMICOLON.". Strictly spoken the error message is correct. However it highlight an important issue, preprocessor directives can cause unterminated statements easily transfer accross natural file boundaries (e.g. #include directives) which makes these source of these statements near impossible to locate, especially in larger code bases where reusabiliity is imminent this class of errors are easilly obfuscated.
```
layout( location = 0 ) out vec4 color1
```
```
layout( location = 0 ) out vec4 color2:
```
```
#include "a"
#include "b"
```
In the above scenario, the origional statement occurs in "a" but the factual error is only detected in "b". I'd propose that unterminated statements could report the location where the statement begins, and the specific token or (sub-)statement location reported as detail(s).
I have some past expierence in compilers and language(s) generation but haven't used yacc before so I'd be happy just get a few pointers. I believe this error is presently automatically generated from the grammer (glslang.y) and isn't explictly generated/handled inline. I suspect the location (simple_statement) needs to propegate so that they can be used during error handling.
Contributor guide
Research direction
Start by reading glslang.y and the issue's examples involving #include and #line. Trace how the grammar reports an error when a statement crosses source boundaries, including the simple_statement location. Done means the diagnostic identifies where the unterminated statement begins while retaining the later token or sub-statement location as detail.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100