From c694e693b098ca624a65815f2481be3223385107 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 14 Oct 2014 20:27:05 +0000 Subject: [PATCH] Patch to warn on interger overflow in presence of implicit casts. Reviewed by Reid Kleckner. rdar://18405357 llvm-svn: 219712 --- clang/lib/Sema/SemaChecking.cpp | 4 ++-- clang/test/Sema/switch-1.c | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 58c626351f9e..a98b87544a6b 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -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(E->IgnoreParens())) - E->EvaluateForOverflow(Context); + if (isa(E->IgnoreParenCasts())) + E->IgnoreParenCasts()->EvaluateForOverflow(Context); } namespace { diff --git a/clang/test/Sema/switch-1.c b/clang/test/Sema/switch-1.c index ce1e7dc9433f..5191c92e714d 100644 --- a/clang/test/Sema/switch-1.c +++ b/clang/test/Sema/switch-1.c @@ -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;