r219712 - Patch to warn on interger overflow in presence of

Fariborz Jahanian fjahanian at apple.com
Tue Oct 14 13:27:05 PDT 2014


Author: fjahanian
Date: Tue Oct 14 15:27:05 2014
New Revision: 219712

URL: http://llvm.org/viewvc/llvm-project?rev=219712&view=rev
Log:
Patch to warn on interger overflow in presence of
implicit casts. Reviewed by Reid Kleckner.
rdar://18405357

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=219712&r1=219711&r2=219712&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Oct 14 15:27:05 2014
@@ -6754,8 +6754,8 @@ void Sema::CheckImplicitConversions(Expr
 /// 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 {

Modified: cfe/trunk/test/Sema/switch-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/switch-1.c?rev=219712&r1=219711&r2=219712&view=diff
==============================================================================
--- cfe/trunk/test/Sema/switch-1.c (original)
+++ cfe/trunk/test/Sema/switch-1.c Tue Oct 14 15:27:05 2014
@@ -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;





More information about the cfe-commits mailing list