diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2013-03-15 16:36:04 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-03-15 16:36:04 +0000 |
commit | 2cd889d6d97db0cf73930873871aa4a542e84b89 (patch) | |
tree | 69b138b321dc6d3e7e834aea8269d066a702e6c8 | |
parent | b7e86be4412635d34b2bf161e1b8bbf00be055c9 (diff) |
c: add the missing binary operatory when checking
for integer overflow. // rdar://13423975
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177162 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 2 | ||||
-rw-r--r-- | test/Sema/switch-1.c | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index be0480b9f1..3926f01ea6 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -5188,7 +5188,7 @@ 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) + if (Opc != BO_Add && Opc != BO_Sub && Opc != BO_Mul && Opc != BO_Div) return; llvm::SmallVector<PartialDiagnosticAt, 4> Diags; E->EvaluateForOverflow(Context, &Diags); diff --git a/test/Sema/switch-1.c b/test/Sema/switch-1.c index 82ce6747a3..944048d1b2 100644 --- a/test/Sema/switch-1.c +++ b/test/Sema/switch-1.c @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin10 %s // RUN: %clang_cc1 -x c++ -fsyntax-only -verify -triple x86_64-apple-darwin10 %s // rdar://11577384 +// rdar://13423975 int f(int i) { switch (i) { @@ -10,6 +11,8 @@ int f(int i) { return 2; 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'}} + return 4; case 2147483647: return 0; } |