Skip to content

Commit 383eaf3

Browse files
authored
Fix token-pasting macros not working in preprocessor directives. (KhronosGroup#2453)
Fixes KhronosGroup#2443
1 parent 3d7984d commit 383eaf3

File tree

3 files changed

+61
-44
lines changed

3 files changed

+61
-44
lines changed

Test/baseResults/tokenPaste.vert.out

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ ERROR: 0:38: '##' : unexpected location
33
ERROR: 0:40: '##' : unexpected location; end of replacement list
44
ERROR: 0:49: '##' : combined tokens are too long
55
ERROR: 0:52: '##' : not supported for these tokens
6-
ERROR: 0:69: '##' : combined token is invalid
7-
ERROR: 0:82: 'macro expansion' : Too few args in Macro rec
8-
ERROR: 0:82: '##' : unexpected location
9-
ERROR: 0:82: '##' : unexpected location
10-
ERROR: 0:86: '##' : unexpected location; end of argument
6+
ERROR: 0:81: '##' : combined token is invalid
7+
ERROR: 0:94: 'macro expansion' : Too few args in Macro rec
8+
ERROR: 0:94: '##' : unexpected location
9+
ERROR: 0:94: '##' : unexpected location
10+
ERROR: 0:98: '##' : unexpected location; end of argument
1111
ERROR: 9 compilation errors. No code generated.
1212

1313

@@ -18,35 +18,35 @@ ERROR: node is still EOpNull!
1818
0:52 'a' ( global int)
1919
0:52 Constant:
2020
0:52 11 (const int)
21-
0:58 Sequence
22-
0:58 move second child to first child ( temp int)
23-
0:58 'cop' ( global int)
24-
0:58 Constant:
25-
0:58 160 (const int)
26-
0:59 Sequence
27-
0:59 move second child to first child ( temp bool)
28-
0:59 'dop' ( global bool)
29-
0:59 Constant:
30-
0:59 true (const bool)
31-
0:63 Function Definition: ShouldntExpandToThis( ( global void)
32-
0:63 Function Parameters:
33-
0:65 Sequence
34-
0:65 Sequence
35-
0:65 move second child to first child ( temp int)
36-
0:65 'e' ( temp int)
37-
0:65 Constant:
38-
0:65 16 (const int)
39-
0:66 right shift second child into first child ( temp int)
40-
0:66 'e' ( temp int)
41-
0:66 Constant:
42-
0:66 2 (const int)
43-
0:69 Sequence
44-
0:69 move second child to first child ( temp bool)
45-
0:69 'f' ( temp bool)
46-
0:69 Compare Greater Than ( temp bool)
47-
0:69 'e' ( temp int)
48-
0:69 Constant:
49-
0:69 5 (const int)
21+
0:70 Sequence
22+
0:70 move second child to first child ( temp int)
23+
0:70 'cop' ( global int)
24+
0:70 Constant:
25+
0:70 160 (const int)
26+
0:71 Sequence
27+
0:71 move second child to first child ( temp bool)
28+
0:71 'dop' ( global bool)
29+
0:71 Constant:
30+
0:71 true (const bool)
31+
0:75 Function Definition: ShouldntExpandToThis( ( global void)
32+
0:75 Function Parameters:
33+
0:77 Sequence
34+
0:77 Sequence
35+
0:77 move second child to first child ( temp int)
36+
0:77 'e' ( temp int)
37+
0:77 Constant:
38+
0:77 16 (const int)
39+
0:78 right shift second child into first child ( temp int)
40+
0:78 'e' ( temp int)
41+
0:78 Constant:
42+
0:78 2 (const int)
43+
0:81 Sequence
44+
0:81 move second child to first child ( temp bool)
45+
0:81 'f' ( temp bool)
46+
0:81 Compare Greater Than ( temp bool)
47+
0:81 'e' ( temp int)
48+
0:81 Constant:
49+
0:81 5 (const int)
5050
0:? Linker Objects
5151
0:? 'SecondExpansion' ( global int)
5252
0:? 'PostPasteExpansion' ( global int)
@@ -60,6 +60,8 @@ ERROR: node is still EOpNull!
6060
0:? 'foo875' ( uniform float)
6161
0:? 'ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345' ( global float)
6262
0:? 'a' ( global int)
63+
0:? 'seahorse_var' ( uniform float)
64+
0:? 'sealion_var' ( uniform float)
6365
0:? 'aop' ( const int)
6466
0:? 10 (const int)
6567
0:? 'bop' ( const int)
@@ -83,16 +85,16 @@ ERROR: node is still EOpNull!
8385
0:52 'a' ( global int)
8486
0:52 Constant:
8587
0:52 11 (const int)
86-
0:58 Sequence
87-
0:58 move second child to first child ( temp int)
88-
0:58 'cop' ( global int)
89-
0:58 Constant:
90-
0:58 160 (const int)
91-
0:59 Sequence
92-
0:59 move second child to first child ( temp bool)
93-
0:59 'dop' ( global bool)
94-
0:59 Constant:
95-
0:59 true (const bool)
88+
0:70 Sequence
89+
0:70 move second child to first child ( temp int)
90+
0:70 'cop' ( global int)
91+
0:70 Constant:
92+
0:70 160 (const int)
93+
0:71 Sequence
94+
0:71 move second child to first child ( temp bool)
95+
0:71 'dop' ( global bool)
96+
0:71 Constant:
97+
0:71 true (const bool)
9698
0:? Linker Objects
9799
0:? 'SecondExpansion' ( global int)
98100
0:? 'PostPasteExpansion' ( global int)
@@ -106,6 +108,8 @@ ERROR: node is still EOpNull!
106108
0:? 'foo875' ( uniform float)
107109
0:? 'ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345' ( global float)
108110
0:? 'a' ( global int)
111+
0:? 'seahorse_var' ( uniform float)
112+
0:? 'sealion_var' ( uniform float)
109113
0:? 'aop' ( const int)
110114
0:? 10 (const int)
111115
0:? 'bop' ( const int)

Test/tokenPaste.vert

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ float simplePaste(ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01234567
5151
// non-identifiers
5252
int a = simplePaste(11,12);
5353

54+
// should work in #if as well
55+
#define seahorse 1
56+
#define sealion 0
57+
#define marine_animal(suffix) (sea ## suffix)
58+
59+
#if marine_animal(horse) // should pass
60+
uniform float seahorse_var;
61+
#endif
62+
#if !marine_animal(lion) // should pass
63+
uniform float sealion_var;
64+
#endif
65+
5466
// operators
5567
#define MAKE_OP(L, R) L ## R
5668
const int aop = 10;

glslang/MachineIndependent/preprocessor/Pp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ int TPpContext::eval(int token, int precedence, bool shortCircuit, int& res, boo
455455
token = scanToken(ppToken);
456456
}
457457
} else {
458+
token = tokenPaste(token, *ppToken);
458459
token = evalToToken(token, shortCircuit, res, err, ppToken);
459460
return eval(token, precedence, shortCircuit, res, err, ppToken);
460461
}

0 commit comments

Comments
 (0)