Fix #1563: Corrupt token when an object macro miscalls a function macro
This commit is contained in:
		
							parent
							
								
									4ee2f75294
								
							
						
					
					
						commit
						4207c97b93
					
				@ -10,6 +10,7 @@ ERROR: 5 compilation errors.  No code generated.
 | 
				
			|||||||
Shader version: 100
 | 
					Shader version: 100
 | 
				
			||||||
ERROR: node is still EOpNull!
 | 
					ERROR: node is still EOpNull!
 | 
				
			||||||
0:?   Linker Objects
 | 
					0:?   Linker Objects
 | 
				
			||||||
 | 
					0:?     'n' ( global highp int)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Linked vertex stage:
 | 
					Linked vertex stage:
 | 
				
			||||||
@ -19,4 +20,5 @@ ERROR: Linking vertex stage: Missing entry point: Each stage requires one entry
 | 
				
			|||||||
Shader version: 100
 | 
					Shader version: 100
 | 
				
			||||||
ERROR: node is still EOpNull!
 | 
					ERROR: node is still EOpNull!
 | 
				
			||||||
0:?   Linker Objects
 | 
					0:?   Linker Objects
 | 
				
			||||||
 | 
					0:?     'n' ( global highp int)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -77,7 +77,7 @@ ERROR: 12:9000: 'preprocessor evaluation' : expected ')'
 | 
				
			|||||||
ERROR: 12:9002: '#if' : unexpected tokens following directive 
 | 
					ERROR: 12:9002: '#if' : unexpected tokens following directive 
 | 
				
			||||||
ERROR: 12:9014: 'FOOOM' : undeclared identifier 
 | 
					ERROR: 12:9014: 'FOOOM' : undeclared identifier 
 | 
				
			||||||
ERROR: 12:9014: '=' :  cannot convert from ' temp float' to ' global int'
 | 
					ERROR: 12:9014: '=' :  cannot convert from ' temp float' to ' global int'
 | 
				
			||||||
ERROR: 12:9016: 'preprocessor evaluation' : can't evaluate expression 
 | 
					ERROR: 12:9015: 'preprocessor evaluation' : can't evaluate expression 
 | 
				
			||||||
ERROR: 12:9016: 'preprocessor evaluation' : bad expression 
 | 
					ERROR: 12:9016: 'preprocessor evaluation' : bad expression 
 | 
				
			||||||
ERROR: 12:9500: 'preprocessor evaluation' : bad expression 
 | 
					ERROR: 12:9500: 'preprocessor evaluation' : bad expression 
 | 
				
			||||||
ERROR: 12:9500: '#if' : unexpected tokens following directive 
 | 
					ERROR: 12:9500: '#if' : unexpected tokens following directive 
 | 
				
			||||||
 | 
				
			|||||||
@ -55,6 +55,12 @@ void foo()
 | 
				
			|||||||
    s . member2 . yyz;
 | 
					    s . member2 . yyz;
 | 
				
			||||||
    s . member2 . xxyz();
 | 
					    s . member2 . xxyz();
 | 
				
			||||||
    s . member2 . yzy;
 | 
					    s . member2 . yzy;
 | 
				
			||||||
                      vec3 a = vec3(0);vec3 b = a . zxyz;vec3 b = a . xxyz;vec3 b = a . yyz;vec3 b = a . xxyz();vec3 b = a .;vec3 b = a . z;
 | 
					            vec3 a = vec3(0);vec3 b = a . zxyz;vec3 b = a . xxyz;vec3 b = a . yyz;vec3 b = a . xxyz();vec3 b = a . yzy;vec3 b = a . z;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     yyz;
 | 
				
			||||||
 | 
					    yzy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -37,7 +37,7 @@ struct S {
 | 
				
			|||||||
#define xyz xxyz
 | 
					#define xyz xxyz
 | 
				
			||||||
#define yzy() yyz
 | 
					#define yzy() yyz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define LIGHTING_COMMON_BRDF() \
 | 
					#define FUN_MAC() \
 | 
				
			||||||
	vec3 a = vec3(0); \
 | 
						vec3 a = vec3(0); \
 | 
				
			||||||
	vec3 b = a.zxyz;  \
 | 
						vec3 b = a.zxyz;  \
 | 
				
			||||||
	vec3 b = a.xyz;   \
 | 
						vec3 b = a.xyz;   \
 | 
				
			||||||
@ -55,5 +55,11 @@ void foo()
 | 
				
			|||||||
    s.member2.yzy();
 | 
					    s.member2.yzy();
 | 
				
			||||||
    s.member2.xyz();
 | 
					    s.member2.xyz();
 | 
				
			||||||
    s.member2.yzy;
 | 
					    s.member2.yzy;
 | 
				
			||||||
	LIGHTING_COMMON_BRDF()
 | 
					    FUN_MAC()
 | 
				
			||||||
 | 
					    yzy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ();
 | 
				
			||||||
 | 
					    yzy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										13
									
								
								glslang/MachineIndependent/preprocessor/Pp.cpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										13
									
								
								glslang/MachineIndependent/preprocessor/Pp.cpp
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -1192,14 +1192,19 @@ MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, b
 | 
				
			|||||||
    TSourceLoc loc = ppToken->loc;  // in case we go to the next line before discovering the error
 | 
					    TSourceLoc loc = ppToken->loc;  // in case we go to the next line before discovering the error
 | 
				
			||||||
    in->mac = macro;
 | 
					    in->mac = macro;
 | 
				
			||||||
    if (macro->functionLike) {
 | 
					    if (macro->functionLike) {
 | 
				
			||||||
        int token = scanToken(ppToken);
 | 
					        // We don't know yet if this will be a successful call of a
 | 
				
			||||||
 | 
					        // function-like macro; need to look for a '(', but without trashing
 | 
				
			||||||
 | 
					        // the passed in ppToken, until we know we are no longer speculative.
 | 
				
			||||||
 | 
					        TPpToken parenToken;
 | 
				
			||||||
 | 
					        int token = scanToken(&parenToken);
 | 
				
			||||||
        if (newLineOkay) {
 | 
					        if (newLineOkay) {
 | 
				
			||||||
            while (token == '\n')
 | 
					            while (token == '\n')
 | 
				
			||||||
                token = scanToken(ppToken);
 | 
					                token = scanToken(&parenToken);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (token != '(') {
 | 
					        if (token != '(') {
 | 
				
			||||||
            // function-like macro called with object-like syntax: okay, don't expand
 | 
					            // Function-like macro called with object-like syntax: okay, don't expand.
 | 
				
			||||||
            UngetToken(token, ppToken);
 | 
					            // (We ate exactly one token that might not be white space; put it back.
 | 
				
			||||||
 | 
					            UngetToken(token, &parenToken);
 | 
				
			||||||
            delete in;
 | 
					            delete in;
 | 
				
			||||||
            return MacroExpandNotStarted;
 | 
					            return MacroExpandNotStarted;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user