[cfe-commits] r39404 - /cfe/cfe/trunk/Lex/PPExpressions.cpp
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:44:01 PDT 2007
Author: clattner
Date: Wed Jul 11 11:44:01 2007
New Revision: 39404
URL: http://llvm.org/viewvc/llvm-project?rev=39404&view=rev
Log:
Catch overflow of negate. This allows us to emit:
t.c:2:17: warning: integer overflow in preprocessor expression
#if -(INTMAX_MAX+1)
^
t.c:2:5: warning: integer overflow in preprocessor expression
#if -(INTMAX_MAX+1)
^
GCC has some seriously confused source locations in this case:
t.c:2:19: warning: integer overflow in preprocessor expression
t.c:2:20: warning: integer overflow in preprocessor expression
column 19/20 are off the end of the line.
Modified:
cfe/cfe/trunk/Lex/PPExpressions.cpp
Modified: cfe/cfe/trunk/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/PPExpressions.cpp?rev=39404&r1=39403&r2=39404&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/PPExpressions.cpp (original)
+++ cfe/cfe/trunk/Lex/PPExpressions.cpp Wed Jul 11 11:44:01 2007
@@ -261,13 +261,26 @@
// 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);
More information about the cfe-commits
mailing list