[Sema] Issue a warning for integer overflow in struct initializer
Clang wasn't issuing a warning when compiling the following code:
struct s {
unsigned x;
} s = {
.x = 4 * 1024 * 1024 * 1024
};
rdar://problem/23399683
Differential Revision: http://reviews.llvm.org/D15097
llvm-svn: 257357
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 98c9ceb..4680bcd 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -7853,6 +7853,10 @@
void Sema::CheckForIntOverflow (Expr *E) {
if (isa<BinaryOperator>(E->IgnoreParenCasts()))
E->IgnoreParenCasts()->EvaluateForOverflow(Context);
+ else if (auto InitList = dyn_cast<InitListExpr>(E))
+ for (Expr *E : InitList->inits())
+ if (isa<BinaryOperator>(E->IgnoreParenCasts()))
+ E->IgnoreParenCasts()->EvaluateForOverflow(Context);
}
namespace {