r177163 - c: Also chek for integer overflow for '%' operator.
Fariborz Jahanian
fjahanian at apple.com
Fri Mar 15 10:03:56 PDT 2013
Author: fjahanian
Date: Fri Mar 15 12:03:56 2013
New Revision: 177163
URL: http://llvm.org/viewvc/llvm-project?rev=177163&view=rev
Log:
c: Also chek for integer overflow for '%' operator.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/switch-1.c
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=177163&r1=177162&r2=177163&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Mar 15 12:03:56 2013
@@ -5188,8 +5188,16 @@ void Sema::CheckImplicitConversions(Expr
void Sema::CheckForIntOverflow (Expr *E) {
if (const BinaryOperator *BExpr = dyn_cast<BinaryOperator>(E->IgnoreParens())) {
unsigned Opc = BExpr->getOpcode();
- if (Opc != BO_Add && Opc != BO_Sub && Opc != BO_Mul && Opc != BO_Div)
- return;
+ switch (Opc) {
+ case BO_Add:
+ case BO_Sub:
+ case BO_Mul:
+ case BO_Div:
+ case BO_Rem:
+ break;
+ default:
+ return;
+ }
llvm::SmallVector<PartialDiagnosticAt, 4> Diags;
E->EvaluateForOverflow(Context, &Diags);
}
Modified: cfe/trunk/test/Sema/switch-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/switch-1.c?rev=177163&r1=177162&r2=177163&view=diff
==============================================================================
--- cfe/trunk/test/Sema/switch-1.c (original)
+++ cfe/trunk/test/Sema/switch-1.c Fri Mar 15 12:03:56 2013
@@ -12,6 +12,7 @@ int f(int i) {
case (123456 *789012) + 1: // expected-warning {{overflow in expression; result is -1375982336 with type 'int'}}
return 3;
case (2147483647*4)/4: // expected-warning {{overflow in expression; result is -4 with type 'int'}}
+ case (2147483647*4)%4: // expected-warning {{overflow in expression; result is -4 with type 'int'}}
return 4;
case 2147483647:
return 0;
More information about the cfe-commits
mailing list