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;
|
sum += 0.2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//no
|
||||||
|
sum += 0.01;
|
||||||
|
#ifdef ON
|
||||||
|
//no
|
||||||
|
sum += 0.02;
|
||||||
|
#else
|
||||||
|
//no
|
||||||
|
sum += 0.03;
|
||||||
|
#endif
|
||||||
|
|
||||||
//no
|
//no
|
||||||
sum + 0.3;
|
sum + 0.3;
|
||||||
|
|
||||||
|
@ -295,13 +295,14 @@ static int CPPundef(yystypepp * yylvalpp)
|
|||||||
} // CPPundef
|
} // CPPundef
|
||||||
|
|
||||||
/* CPPelse -- skip forward to appropriate spot. This is actually used
|
/* 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
|
** #elif, or #endif after a #if/#ifdef/#ifndef/#elif test was false
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int CPPelse(int matchelse, yystypepp * yylvalpp)
|
static int CPPelse(int matchelse, yystypepp * yylvalpp)
|
||||||
{
|
{
|
||||||
int atom,depth=0;
|
int atom;
|
||||||
|
int depth = 0;
|
||||||
int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||||
|
|
||||||
while (token > 0) {
|
while (token > 0) {
|
||||||
@ -312,25 +313,30 @@ static int CPPelse(int matchelse, yystypepp * yylvalpp)
|
|||||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((token = cpp->currentInput->scan(cpp->currentInput, yylvalpp)) != CPP_IDENTIFIER)
|
if ((token = cpp->currentInput->scan(cpp->currentInput, yylvalpp)) != CPP_IDENTIFIER)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
atom = yylvalpp->sc_ident;
|
atom = yylvalpp->sc_ident;
|
||||||
if (atom == ifAtom || atom == ifdefAtom || atom == ifndefAtom){
|
if (atom == ifAtom || atom == ifdefAtom || atom == ifndefAtom) {
|
||||||
depth++; cpp->ifdepth++; cpp->elsetracker++;
|
depth++;
|
||||||
}
|
cpp->ifdepth++;
|
||||||
else if (atom == endifAtom) {
|
cpp->elsetracker++;
|
||||||
if(--depth<=0){
|
} else if (atom == endifAtom) {
|
||||||
cpp->elsedepth[cpp->elsetracker]=0;
|
if (depth == 0) {
|
||||||
|
// found the #endif we are looking for
|
||||||
|
cpp->elsedepth[cpp->elsetracker] = 0;
|
||||||
--cpp->elsetracker;
|
--cpp->elsetracker;
|
||||||
if (cpp->ifdepth)
|
if (cpp->ifdepth)
|
||||||
--cpp->ifdepth;
|
--cpp->ifdepth;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
--depth;
|
||||||
--cpp->elsetracker;
|
--cpp->elsetracker;
|
||||||
--cpp->ifdepth;
|
--cpp->ifdepth;
|
||||||
}
|
} else if (matchelse && depth == 0) {
|
||||||
else if (((int)(matchelse) != 0)&& depth==0) {
|
|
||||||
if (atom == elseAtom ) {
|
if (atom == elseAtom ) {
|
||||||
|
// found the #else we are looking for
|
||||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||||
if (token != '\n') {
|
if (token != '\n') {
|
||||||
CPPWarningToInfoLog("unexpected tokens following #else preprocessor directive - expected a newline");
|
CPPWarningToInfoLog("unexpected tokens following #else preprocessor directive - expected a newline");
|
||||||
@ -338,22 +344,22 @@ static int CPPelse(int matchelse, yystypepp * yylvalpp)
|
|||||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
} else if (atom == elifAtom) {
|
||||||
else if (atom == elifAtom) {
|
|
||||||
/* we decrement cpp->ifdepth here, because CPPif will increment
|
/* we decrement cpp->ifdepth here, because CPPif will increment
|
||||||
* it and we really want to leave it alone */
|
* it and we really want to leave it alone */
|
||||||
if (cpp->ifdepth){
|
if (cpp->ifdepth) {
|
||||||
--cpp->ifdepth;
|
--cpp->ifdepth;
|
||||||
--cpp->elsetracker;
|
--cpp->elsetracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CPPif(yylvalpp);
|
return CPPif(yylvalpp);
|
||||||
}
|
}
|
||||||
}
|
} else if((atom == elseAtom) && (!ChkCorrectElseNesting())) {
|
||||||
else if((atom==elseAtom) && (!ChkCorrectElseNesting())){
|
|
||||||
CPPErrorToInfoLog("#else after a #else");
|
CPPErrorToInfoLog("#else after a #else");
|
||||||
cpp->CompileError=1;
|
cpp->CompileError=1;
|
||||||
}
|
}
|
||||||
};
|
}; // end while
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user