diff options
-rw-r--r-- | lib/Lex/PPExpressions.cpp | 18 | ||||
-rw-r--r-- | test/Preprocessor/expr_liveness.c | 7 |
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp index 398567be36..6317015137 100644 --- a/lib/Lex/PPExpressions.cpp +++ b/lib/Lex/PPExpressions.cpp @@ -433,20 +433,28 @@ static bool EvaluateDirectiveSubExpr(llvm::APSInt &LHS, unsigned MinPrec, default: assert(0 && "Unknown operator token!"); case tok::percent: if (RHS == 0) { - if (ValueLive) PP.Diag(OpToken, diag::err_pp_remainder_by_zero); - return true; + if (ValueLive) { + PP.Diag(OpToken, diag::err_pp_remainder_by_zero); + return true; + } + } else { + Res = LHS % RHS; } - Res = LHS % RHS; break; case tok::slash: if (RHS == 0) { - if (ValueLive) PP.Diag(OpToken, diag::err_pp_division_by_zero); - return true; + if (ValueLive) { + PP.Diag(OpToken, diag::err_pp_division_by_zero); + return true; + } + break; } + Res = LHS / RHS; if (LHS.isSigned()) Overflow = LHS.isMinSignedValue() && RHS.isAllOnesValue(); // MININT/-1 break; + case tok::star: Res = LHS * RHS; if (LHS != 0 && RHS != 0) diff --git a/test/Preprocessor/expr_liveness.c b/test/Preprocessor/expr_liveness.c index f14ac0a913..61c073204c 100644 --- a/test/Preprocessor/expr_liveness.c +++ b/test/Preprocessor/expr_liveness.c @@ -20,6 +20,13 @@ bar #if 0 ? 124/0 : 42 #endif +// PR2279 +#if 0 ? 1/0: 2 +#else +#error +#endif + + #else |