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:
@@ -163,6 +163,11 @@ static int IfStatement (void)
|
|||||||
Label1 = GetLocalLabel ();
|
Label1 = GetLocalLabel ();
|
||||||
TestResult = TestInParens (Label1, 0);
|
TestResult = TestInParens (Label1, 0);
|
||||||
|
|
||||||
|
/* Output a warning if the condition is always false */
|
||||||
|
if (TestResult == TESTEXPR_FALSE) {
|
||||||
|
UnreachableCodeWarning ();
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse the if body */
|
/* Parse the if body */
|
||||||
StmtFlags = AnyStatement (0, 0);
|
StmtFlags = AnyStatement (0, 0);
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@
|
|||||||
unsigned Test (unsigned Label, int Invert)
|
unsigned Test (unsigned Label, int Invert)
|
||||||
/* Evaluate a boolean test expression and jump depending on the result of
|
/* 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
|
** 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;
|
ExprDesc Expr;
|
||||||
@@ -74,10 +74,7 @@ unsigned Test (unsigned Label, int Invert)
|
|||||||
Result = (Expr.IVal != 0) ? TESTEXPR_TRUE : TESTEXPR_FALSE;
|
Result = (Expr.IVal != 0) ? TESTEXPR_TRUE : TESTEXPR_FALSE;
|
||||||
|
|
||||||
/* Constant rvalue */
|
/* Constant rvalue */
|
||||||
if (!Invert && Expr.IVal == 0) {
|
if ((!Invert && Expr.IVal == 0) || (Invert && Expr.IVal != 0)) {
|
||||||
g_jump (Label);
|
|
||||||
UnreachableCodeWarning ();
|
|
||||||
} else if (Invert && Expr.IVal != 0) {
|
|
||||||
g_jump (Label);
|
g_jump (Label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,8 +122,7 @@ unsigned Test (unsigned Label, int Invert)
|
|||||||
unsigned TestInParens (unsigned Label, int Invert)
|
unsigned TestInParens (unsigned Label, int Invert)
|
||||||
/* Evaluate a boolean test expression in parenthesis and jump depending on
|
/* 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
|
** 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
|
** TESTEXPR_xx codes defined above.
|
||||||
** output.
|
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
unsigned Result;
|
unsigned Result;
|
||||||
|
|||||||
@@ -59,14 +59,13 @@
|
|||||||
unsigned Test (unsigned Label, int Invert);
|
unsigned Test (unsigned Label, int Invert);
|
||||||
/* Evaluate a boolean test expression and jump depending on the result of
|
/* 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
|
** 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);
|
unsigned TestInParens (unsigned Label, int Invert);
|
||||||
/* Evaluate a boolean test expression in parenthesis and jump depending on
|
/* 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
|
** 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
|
** TESTEXPR_xx codes defined above.
|
||||||
** output.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user