Move the warning about unreachable code out of the Test() function and into
the callers. This has the effect that the location for the warning is much more precise than before.
This commit is contained in:
@@ -425,31 +425,31 @@ void UnreachableCodeWarning (void)
|
||||
{
|
||||
if (IS_Get (&WarnUnreachableCode)) {
|
||||
|
||||
LineInfo* LI;
|
||||
LineInfo* LI;
|
||||
|
||||
/* Add special handling for compound statements if the current token
|
||||
** is from the source. Doing this here is a bit hacky but unfortunately
|
||||
** there's no better place.
|
||||
*/
|
||||
if (CurTok.LI && NextTok.LI) {
|
||||
if (CurTok.Tok == TOK_LCURLY) {
|
||||
/* Do not point to the compoung statement but to the first
|
||||
** statement within it. If the compound statement is empty
|
||||
** do not even output a warning. This fails of course for
|
||||
** nested compounds but will do the right thing in most cases.
|
||||
*/
|
||||
if (NextTok.Tok == TOK_RCURLY) {
|
||||
return;
|
||||
}
|
||||
LI = NextTok.LI;
|
||||
} else {
|
||||
LI = CurTok.LI;
|
||||
}
|
||||
} else {
|
||||
LI = GetCurLineInfo ();
|
||||
}
|
||||
/* Add special handling for compound statements if the current token
|
||||
** is from the source. Doing this here is a bit hacky but unfortunately
|
||||
** there's no better place.
|
||||
*/
|
||||
if (CurTok.LI && NextTok.LI) {
|
||||
if (CurTok.Tok == TOK_LCURLY) {
|
||||
/* Do not point to the compoung statement but to the first
|
||||
** statement within it. If the compound statement is empty
|
||||
** do not even output a warning. This fails of course for
|
||||
** nested compounds but will do the right thing in most cases.
|
||||
*/
|
||||
if (NextTok.Tok == TOK_RCURLY) {
|
||||
return;
|
||||
}
|
||||
LI = NextTok.LI;
|
||||
} else {
|
||||
LI = CurTok.LI;
|
||||
}
|
||||
} else {
|
||||
LI = GetCurLineInfo ();
|
||||
}
|
||||
|
||||
/* Now output the warning */
|
||||
/* Now output the warning */
|
||||
LIWarning (EC_PARSER, LI, "Unreachable code");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +163,11 @@ static int IfStatement (void)
|
||||
Label1 = GetLocalLabel ();
|
||||
TestResult = TestInParens (Label1, 0);
|
||||
|
||||
/* Output a warning if the condition is always false */
|
||||
if (TestResult == TESTEXPR_FALSE) {
|
||||
UnreachableCodeWarning ();
|
||||
}
|
||||
|
||||
/* Parse the if body */
|
||||
StmtFlags = AnyStatement (0, 0);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
unsigned Test (unsigned Label, int Invert)
|
||||
/* Evaluate a boolean test expression and jump depending on the result of
|
||||
** the test and on Invert. The function returns one of the TESTEXPR_xx codes
|
||||
** defined above. If the jump is always true, a warning is output.
|
||||
** defined above.
|
||||
*/
|
||||
{
|
||||
ExprDesc Expr;
|
||||
@@ -74,10 +74,7 @@ unsigned Test (unsigned Label, int Invert)
|
||||
Result = (Expr.IVal != 0) ? TESTEXPR_TRUE : TESTEXPR_FALSE;
|
||||
|
||||
/* Constant rvalue */
|
||||
if (!Invert && Expr.IVal == 0) {
|
||||
g_jump (Label);
|
||||
UnreachableCodeWarning ();
|
||||
} else if (Invert && Expr.IVal != 0) {
|
||||
if ((!Invert && Expr.IVal == 0) || (Invert && Expr.IVal != 0)) {
|
||||
g_jump (Label);
|
||||
}
|
||||
|
||||
@@ -125,8 +122,7 @@ unsigned Test (unsigned Label, int Invert)
|
||||
unsigned TestInParens (unsigned Label, int Invert)
|
||||
/* Evaluate a boolean test expression in parenthesis and jump depending on
|
||||
** the result of the test * and on Invert. The function returns one of the
|
||||
** TESTEXPR_xx codes defined above. If the jump is always true, a warning is
|
||||
** output.
|
||||
** TESTEXPR_xx codes defined above.
|
||||
*/
|
||||
{
|
||||
unsigned Result;
|
||||
|
||||
@@ -59,14 +59,13 @@
|
||||
unsigned Test (unsigned Label, int Invert);
|
||||
/* Evaluate a boolean test expression and jump depending on the result of
|
||||
** the test and on Invert. The function returns one of the TESTEXPR_xx codes
|
||||
** defined above. If the jump is always true, a warning is output.
|
||||
** defined above.
|
||||
*/
|
||||
|
||||
unsigned TestInParens (unsigned Label, int Invert);
|
||||
/* Evaluate a boolean test expression in parenthesis and jump depending on
|
||||
** the result of the test * and on Invert. The function returns one of the
|
||||
** TESTEXPR_xx codes defined above. If the jump is always true, a warning is
|
||||
** output.
|
||||
** TESTEXPR_xx codes defined above.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user