Currently we do not warn Integer overflow in presence of casts; as in:
unsigned long long l = 65536 * 65536;

This small patch fixes it:

Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp   (revision 219686)
+++ lib/Sema/SemaChecking.cpp   (working copy)
@@ -6754,8 +6754,8 @@
 /// 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: test/Sema/switch-1.c
===================================================================
--- test/Sema/switch-1.c        (revision 219686)
+++ test/Sema/switch-1.c        (working copy)
@@ -20,3 +20,8 @@
   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;

Also, is there a reason we do not warn on overflow for unsigned; as in:
unsigned long long l2 = 65536 * (unsigned)65536;
Even though resulting constant is the unexpected 0.

- Please review and comment.

- Thanks, Fariborz

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to