r177162 - c: add the missing binary operatory when checking
Fariborz Jahanian
fjahanian at apple.com
Fri Mar 15 09:36:04 PDT 2013
Author: fjahanian
Date: Fri Mar 15 11:36:04 2013
New Revision: 177162
URL: http://llvm.org/viewvc/llvm-project?rev=177162&view=rev
Log:
c: add the missing binary operatory when checking
for integer overflow. // rdar://13423975
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=177162&r1=177161&r2=177162&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Mar 15 11:36:04 2013
@@ -5188,7 +5188,7 @@ 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)
+ if (Opc != BO_Add && Opc != BO_Sub && Opc != BO_Mul && Opc != BO_Div)
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=177162&r1=177161&r2=177162&view=diff
==============================================================================
--- cfe/trunk/test/Sema/switch-1.c (original)
+++ cfe/trunk/test/Sema/switch-1.c Fri Mar 15 11:36:04 2013
@@ -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;
}
More information about the cfe-commits
mailing list