]> granicus.if.org Git - clang/commitdiff
c: Also chek for integer overflow for '%' operator.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 15 Mar 2013 17:03:56 +0000 (17:03 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 15 Mar 2013 17:03:56 +0000 (17:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177163 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/switch-1.c

index 3926f01ea66225bee99b1ef56f085cc60798899e..2f8d8576b9d28b1628761d8fd09ade85037764f2 100644 (file)
@@ -5188,8 +5188,16 @@ void Sema::CheckImplicitConversions(Expr *E, SourceLocation CC) {
 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);
   }
index 944048d1b2819b6d10f14751aeb73fdd981b5b2f..ce1e7dc9433fed723674e9beda7a32d3d478f4a4 100644 (file)
@@ -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;