[cfe-commits] r39403 - /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: 39403

URL: http://llvm.org/viewvc/llvm-project?rev=39403&view=rev
Log:
Overflow detection for +/-

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=39403&r1=39402&r2=39403&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/PPExpressions.cpp (original)
+++ cfe/cfe/trunk/Lex/PPExpressions.cpp Wed Jul 11 11:44:01 2007
@@ -467,9 +467,19 @@
     }
     case tok::plus:
       Res = LHS + RHS;
+      if (LHS.isUnsigned())
+        Overflow = Res.ult(LHS);
+      else if (LHS.isPositive() == RHS.isPositive() &&
+               Res.isPositive() != LHS.isPositive())
+        Overflow = true;  // Overflow for signed addition.
       break;
     case tok::minus:
       Res = LHS - RHS;
+      if (LHS.isUnsigned())
+        Overflow = Res.ugt(LHS);
+      else if (LHS.isPositive() != RHS.isPositive() &&
+               Res.isPositive() != LHS.isPositive())
+        Overflow = true;  // Overflow for signed subtraction.
       break;
     case tok::lessequal:
       Res = LHS <= RHS;





More information about the cfe-commits mailing list