[cfe-commits] r39405 - /cfe/cfe/trunk/Lex/PPExpressions.cpp
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:44:02 PDT 2007
Author: clattner
Date: Wed Jul 11 11:44:01 2007
New Revision: 39405
URL: http://llvm.org/viewvc/llvm-project?rev=39405&view=rev
Log:
Overflow detection for multiply and divide. Fix a bug handling 'usual
arithmetic conversions'.
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=39405&r1=39404&r2=39405&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/PPExpressions.cpp (original)
+++ cfe/cfe/trunk/Lex/PPExpressions.cpp Wed Jul 11 11:44:01 2007
@@ -428,14 +428,15 @@
// Usual arithmetic conversions (C99 6.3.1.8p1): result is unsigned if
// either operand is unsigned. Don't do this for x and y in "x ? y : z".
+ APSInt Res(LHS.getBitWidth());
if (Operator != tok::question) {
if (RHS.isUnsigned()) LHS.setIsUnsigned(true);
RHS.setIsUnsigned(LHS.isUnsigned());
+ Res.setIsUnsigned(LHS.isUnsigned());
}
// FIXME: All of these should detect and report overflow??
bool Overflow = false;
- APSInt Res(LHS.getBitWidth());
switch (Operator) {
default: assert(0 && "Unknown operator token!");
case tok::percent:
@@ -451,9 +452,13 @@
return true;
}
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)
+ Overflow = Res/RHS != LHS || Res/LHS != RHS;
break;
case tok::lessless: {
// Determine whether overflow is about to happen.
More information about the cfe-commits
mailing list