KhronosGroup / KhronosGroup/glslang
Apparent C vs GLSLang preprocessor differences
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
```c
#include "stdio.h"
#include "stdbool.h"
#define CONCAT3_IMPLX(x, y, z) x##y##z
#define CONCAT3_IMPL1(x, y, z) CONCAT3_IMPLX(x, y, z)
#define CONCAT3_IMPL0(x, y, z) CONCAT3_IMPL1(x, y, z)
#define CONCAT3(x, y, z) CONCAT3_IMPL0(x, y, z)
#define USE_FOO_PUSH_CONSTANTS true
#define THING_NAME FOO
#if CONCAT3(USE_,THING_NAME,_PUSH_CONSTANTS) == true
void Foo() { puts("It worked"); }
#else
void Foo() { puts("It didn't work"); }
#endif
int main() {
Foo();
return 0;
}
```
```
Program returned: 0
Program stdout
It worked
```
vs
```glsl
// This will be consumed as a .glsl file and needs the stage and target profile. Example options:
// -S comp --target-env vulkan1.2
#version 450
#extension GL_EXT_shader_explicit_arithmetic_types_int32 : require
#define U32 uint32_t
#define CONCAT3_IMPLX(x, y, z) x##y##z
#define CONCAT3_IMPL1(x, y, z) CONCAT3_IMPLX(x, y, z)
#define CONCAT3_IMPL0(x, y, z) CONCAT3_IMPL1(x, y, z)
#define CONCAT3(x, y, z) CONCAT3_IMPL0(x, y, z)
#define USE_FOO_PUSH_CONSTANTS true
#define THING_NAME FOO
#if CONCAT3(USE_,THING_NAME,_PUSH_CONSTANTS) == true
U32 Foo() { return 1; }
#else
U32 Foo() { return 0; }
#endif
void main() {
U32 a = Foo();
}
```
```
:17: '#if' : unexpected tokens following directive
:17: '' : missing #endif
:17: '' : compilation terminated
3 compilation errors. No code generated.
Linking compute stage: Missing entry point: Each stage requires one entry point
SPIR-V is not generated for failed compile or link
Compiler returned: 2
```
nani
Contributor guide
Research direction
No repository file or test is named. Start by reproducing the linked C and GLSL Compiler Explorer cases, then trace glslang's preprocessor handling of the token-pasted #if expression; done means establishing the expected behavior and covering the discrepancy with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100