Fix a preprocessor defect, where nested dead #if-#endif had nesting depth off by one level, turning what should be dead code into live code.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@20461 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
464f6d9ff1
commit
85e0e02f6f
@ -38,6 +38,16 @@ sum += 50000.0;
|
||||
sum += 0.2;
|
||||
#endif
|
||||
|
||||
//no
|
||||
sum += 0.01;
|
||||
#ifdef ON
|
||||
//no
|
||||
sum += 0.02;
|
||||
#else
|
||||
//no
|
||||
sum += 0.03;
|
||||
#endif
|
||||
|
||||
//no
|
||||
sum + 0.3;
|
||||
|
||||
|
@ -295,65 +295,71 @@ static int CPPundef(yystypepp * yylvalpp)
|
||||
} // CPPundef
|
||||
|
||||
/* CPPelse -- skip forward to appropriate spot. This is actually used
|
||||
** to skip to and #endif after seeing an #else, AND to skip to a #else,
|
||||
** to skip to a #endif after seeing an #else, AND to skip to a #else,
|
||||
** #elif, or #endif after a #if/#ifdef/#ifndef/#elif test was false
|
||||
*/
|
||||
|
||||
static int CPPelse(int matchelse, yystypepp * yylvalpp)
|
||||
{
|
||||
int atom,depth=0;
|
||||
int atom;
|
||||
int depth = 0;
|
||||
int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||
|
||||
while (token > 0) {
|
||||
|
||||
while (token > 0) {
|
||||
if (token != '#') {
|
||||
while (token != '\n')
|
||||
while (token != '\n')
|
||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||
|
||||
|
||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||
continue;
|
||||
}
|
||||
if ((token = cpp->currentInput->scan(cpp->currentInput, yylvalpp)) != CPP_IDENTIFIER)
|
||||
continue;
|
||||
|
||||
if ((token = cpp->currentInput->scan(cpp->currentInput, yylvalpp)) != CPP_IDENTIFIER)
|
||||
continue;
|
||||
|
||||
atom = yylvalpp->sc_ident;
|
||||
if (atom == ifAtom || atom == ifdefAtom || atom == ifndefAtom){
|
||||
depth++; cpp->ifdepth++; cpp->elsetracker++;
|
||||
}
|
||||
else if (atom == endifAtom) {
|
||||
if(--depth<=0){
|
||||
cpp->elsedepth[cpp->elsetracker]=0;
|
||||
--cpp->elsetracker;
|
||||
if (atom == ifAtom || atom == ifdefAtom || atom == ifndefAtom) {
|
||||
depth++;
|
||||
cpp->ifdepth++;
|
||||
cpp->elsetracker++;
|
||||
} else if (atom == endifAtom) {
|
||||
if (depth == 0) {
|
||||
// found the #endif we are looking for
|
||||
cpp->elsedepth[cpp->elsetracker] = 0;
|
||||
--cpp->elsetracker;
|
||||
if (cpp->ifdepth)
|
||||
--cpp->ifdepth;
|
||||
break;
|
||||
}
|
||||
--cpp->elsetracker;
|
||||
--cpp->ifdepth;
|
||||
}
|
||||
else if (((int)(matchelse) != 0)&& depth==0) {
|
||||
if (atom == elseAtom ) {
|
||||
--depth;
|
||||
--cpp->elsetracker;
|
||||
--cpp->ifdepth;
|
||||
} else if (matchelse && depth == 0) {
|
||||
if (atom == elseAtom ) {
|
||||
// found the #else we are looking for
|
||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||
if (token != '\n') {
|
||||
CPPWarningToInfoLog("unexpected tokens following #else preprocessor directive - expected a newline");
|
||||
while (token != '\n')
|
||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (atom == elifAtom) {
|
||||
break;
|
||||
} else if (atom == elifAtom) {
|
||||
/* we decrement cpp->ifdepth here, because CPPif will increment
|
||||
* it and we really want to leave it alone */
|
||||
if (cpp->ifdepth){
|
||||
--cpp->ifdepth;
|
||||
--cpp->elsetracker;
|
||||
}
|
||||
* it and we really want to leave it alone */
|
||||
if (cpp->ifdepth) {
|
||||
--cpp->ifdepth;
|
||||
--cpp->elsetracker;
|
||||
}
|
||||
|
||||
return CPPif(yylvalpp);
|
||||
}
|
||||
}
|
||||
else if((atom==elseAtom) && (!ChkCorrectElseNesting())){
|
||||
} else if((atom == elseAtom) && (!ChkCorrectElseNesting())) {
|
||||
CPPErrorToInfoLog("#else after a #else");
|
||||
cpp->CompileError=1;
|
||||
}
|
||||
};
|
||||
}; // end while
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user