]> granicus.if.org Git - clang/commitdiff
Patch to warn on interger overflow in presence of
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 14 Oct 2014 20:27:05 +0000 (20:27 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 14 Oct 2014 20:27:05 +0000 (20:27 +0000)
implicit casts. Reviewed by Reid Kleckner.
rdar://18405357

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219712 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 58c626351f9eca4d89e84b0293c386ff1701ee41..a98b87544a6b043d488437d5b8073ffb8556f6f4 100644 (file)
@@ -6754,8 +6754,8 @@ void Sema::CheckImplicitConversions(Expr *E, SourceLocation CC) {
 /// Diagnose when expression is an integer constant expression and its evaluation
 /// results in integer overflow
 void Sema::CheckForIntOverflow (Expr *E) {
-  if (isa<BinaryOperator>(E->IgnoreParens()))
-    E->EvaluateForOverflow(Context);
+  if (isa<BinaryOperator>(E->IgnoreParenCasts()))
+    E->IgnoreParenCasts()->EvaluateForOverflow(Context);
 }
 
 namespace {
index ce1e7dc9433fed723674e9beda7a32d3d478f4a4..5191c92e714db8974c1c04322a2e3cb7a59707bc 100644 (file)
@@ -20,3 +20,8 @@ int f(int i) {
   return (i, 65537) * 65537; // expected-warning {{overflow in expression; result is 131073 with type 'int'}} \
                             // expected-warning {{expression result unused}}
 }
+
+// rdar://18405357
+unsigned long long l = 65536 * 65536; // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+unsigned long long l2 = 65536 * (unsigned)65536;
+unsigned long long l3 = 65536 * 65536ULL;