diff --git a/clang/Lex/PPExpressions.cpp b/clang/Lex/PPExpressions.cpp index 4c17dd1be8b54d4401161a36d77ed432b86f6517..a012d8fe7b8d02d6edb8e9b604e99fb06d651d17 100644 --- a/clang/Lex/PPExpressions.cpp +++ b/clang/Lex/PPExpressions.cpp @@ -261,13 +261,26 @@ static bool EvaluateValue(APSInt &Result, LexerToken &PeekTok, // Unary plus doesn't modify the value. PP.LexNonComment(PeekTok); return EvaluateValue(Result, PeekTok, DT, ValueLive, PP); - case tok::minus: + case tok::minus: { + SourceLocation Loc = PeekTok.getLocation(); PP.LexNonComment(PeekTok); if (EvaluateValue(Result, PeekTok, DT, ValueLive, PP)) return true; // C99 6.5.3.3p3: The sign of the result matches the sign of the operand. Result = -Result; + + bool Overflow = false; + if (Result.isUnsigned()) + Overflow = !Result.isPositive(); + else if (Result.isMinSignedValue()) + Overflow = true; // -MININT is the only thing that overflows. + + // If this operator is live and overflowed, report the issue. + if (Overflow && ValueLive) + PP.Diag(Loc, diag::warn_pp_expr_overflow); + DT.State = DefinedTracker::Unknown; return false; + } case tok::tilde: PP.LexNonComment(PeekTok);