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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257357
91177308-0d34-0410-b5e6-
96231b3b80d8
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 {
// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
}
+
+struct s {
+ unsigned x;
+ unsigned y;
+} s = {
+ .y = 5,
+ .x = 4 * 1024 * 1024 * 1024 // expected-warning {{overflow in expression; result is 0 with type 'int'}}
+};