diff options
author | Chris Lattner <sabre@nondot.org> | 2008-07-03 03:47:30 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-07-03 03:47:30 +0000 |
commit | 1cb0e61e985e80a11f083d437836d7c223cfab09 (patch) | |
tree | b6d81d3fd29d4988f07c8f6671786ba0a79b2485 /clang/lib/Lex/PPExpressions.cpp | |
parent | 9ff58d7cafa8fe695ae838b3decc027c5c9169d4 (diff) | |
download | bcm5719-llvm-1cb0e61e985e80a11f083d437836d7c223cfab09.tar.gz bcm5719-llvm-1cb0e61e985e80a11f083d437836d7c223cfab09.zip |
Fix PR2252: don't warn on negating an unsigned value ever, and don't emit
'integer constant is so large that it is unsigned' warning for hex literals.
llvm-svn: 53070
Diffstat (limited to 'clang/lib/Lex/PPExpressions.cpp')
-rw-r--r-- | clang/lib/Lex/PPExpressions.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp index 5f11df08936..2a4794de835 100644 --- a/clang/lib/Lex/PPExpressions.cpp +++ b/clang/lib/Lex/PPExpressions.cpp @@ -198,7 +198,8 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, // large that it is unsigned" e.g. on 12345678901234567890 where intmax_t // is 64-bits. if (!Literal.isUnsigned && Result.Val.isNegative()) { - if (ValueLive) + // Don't warn for a hex literal: 0x8000..0 shouldn't warn. + if (ValueLive && Literal.getRadix() != 16) PP.Diag(PeekTok, diag::warn_integer_too_large_for_signed); Result.Val.setIsUnsigned(true); } @@ -288,11 +289,8 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, // C99 6.5.3.3p3: The sign of the result matches the sign of the operand. Result.Val = -Result.Val; - bool Overflow = false; - if (Result.isUnsigned()) - Overflow = Result.Val.isNegative(); - else if (Result.Val.isMinSignedValue()) - Overflow = true; // -MININT is the only thing that overflows. + // -MININT is the only thing that overflows. Unsigned never overflows. + bool Overflow = !Result.isUnsigned() && Result.Val.isMinSignedValue(); // If this operator is live and overflowed, report the issue. if (Overflow && ValueLive) |