Fix some issues with signedness in preprocessor expressions. Do also disallow
comma expressions since the aren't compliant and collide with macro invocations.
This commit is contained in:
@@ -55,7 +55,6 @@ static int PPEvaluationFailed = 0;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void PPhie0 (PPExpr* Expr);
|
|
||||||
static void PPhie1 (PPExpr* Expr);
|
static void PPhie1 (PPExpr* Expr);
|
||||||
|
|
||||||
|
|
||||||
@@ -138,7 +137,7 @@ static void PPhiePrimary (PPExpr* Expr)
|
|||||||
** recursively.
|
** recursively.
|
||||||
*/
|
*/
|
||||||
NextToken ();
|
NextToken ();
|
||||||
PPhie0 (Expr);
|
PPhie1 (Expr);
|
||||||
ConsumeRParen ();
|
ConsumeRParen ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -263,6 +262,7 @@ void PPhie10 (PPExpr* Expr)
|
|||||||
NextToken ();
|
NextToken ();
|
||||||
PPhie10 (Expr);
|
PPhie10 (Expr);
|
||||||
Expr->IVal = !Expr->IVal;
|
Expr->IVal = !Expr->IVal;
|
||||||
|
Expr->Flags &= ~PPEXPR_UNSIGNED; /* Result is signed */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_CEOF:
|
case TOK_CEOF:
|
||||||
@@ -424,10 +424,10 @@ static void PPhie_compare (const token_t* Ops, /* List of generators */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* The result is signed */
|
/* The result is signed */
|
||||||
Expr->Flags &= ~PPEXPR_UNSIGNED;
|
Expr->Flags &= ~PPEXPR_UNSIGNED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -711,7 +711,7 @@ static void PPhieQuest (PPExpr* Expr)
|
|||||||
|
|
||||||
/* Parse second expression */
|
/* Parse second expression */
|
||||||
PPExprInit (&Expr2);
|
PPExprInit (&Expr2);
|
||||||
PPhie0 (&Expr2);
|
PPhie1 (&Expr2);
|
||||||
|
|
||||||
/* Skip the colon */
|
/* Skip the colon */
|
||||||
ConsumeColon ();
|
ConsumeColon ();
|
||||||
@@ -809,23 +809,6 @@ static void PPhie1 (PPExpr* Expr)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void PPhie0 (PPExpr* Expr)
|
|
||||||
/* Handle the comma "," operator */
|
|
||||||
{
|
|
||||||
PPhie1 (Expr);
|
|
||||||
|
|
||||||
while (CurTok.Tok == TOK_COMMA) {
|
|
||||||
/* Skip the comma */
|
|
||||||
NextToken ();
|
|
||||||
/* Reset the expression */
|
|
||||||
PPExprInit (Expr);
|
|
||||||
/* Use the next operand as the value instead */
|
|
||||||
PPhie1 (Expr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ParsePPExprInLine (PPExpr* Expr)
|
void ParsePPExprInLine (PPExpr* Expr)
|
||||||
/* Parse a line for PP expression */
|
/* Parse a line for PP expression */
|
||||||
{
|
{
|
||||||
@@ -836,7 +819,7 @@ void ParsePPExprInLine (PPExpr* Expr)
|
|||||||
|
|
||||||
/* Parse */
|
/* Parse */
|
||||||
PPExprInit (Expr);
|
PPExprInit (Expr);
|
||||||
PPhie0 (Expr);
|
PPhie1 (Expr);
|
||||||
|
|
||||||
/* If the evaluation fails, the result is always zero */
|
/* If the evaluation fails, the result is always zero */
|
||||||
if (PPEvaluationFailed) {
|
if (PPEvaluationFailed) {
|
||||||
|
|||||||
3
test/err/bug2523.c
Normal file
3
test/err/bug2523.c
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#if (1, 0) < 0
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
29
test/val/bug2523.c
Normal file
29
test/val/bug2523.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#if (0u - 1) < 0
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !1u - 1 > 0
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (1 & 1u) - 2 < 0
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (1 | 1u) - 2 < 0
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (1 ^ 1u) - 2 < 0
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (1u >> 1) - 2 < 0
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (0u << 1) - 1 < 0
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main() { return 0; }
|
||||||
Reference in New Issue
Block a user