jmagee added you to the CC list for the revision "Catch more cases when
diagnosing integer-constant-expression overflows.".
Hi,
This patch improves integer-constant-expression overflow diagnostics.
Currently clang catches overflow in some cases:
int i;
...
switch (i) {
case 4096 * 1024 * 1024: // Generates overflow warning
...
}
if (4096 * 1024 * 1024) { // Generates overflow warning
}
But it misses other cases:
uint64_t x = 4096 * 1024 * 1024; // no warning
if ((x = 4096 * 1024 * 1024)) { // no warning
}
switch (i) {
case (uint64_t)(4096 * 1024 * 1024): // no warning
...
}
void f1(int);
...
f1(4096 * 1024 * 1024); // no warning
The patch introduces the following changes:
1) In Sema::CheckForIntOverflow, when checking for a BinaryOperator ignore
any casts in addition to parentheses.
Ignoring only parentheses was not enough because it missed cases like:
x = 4608 * 1024 * 1024, which has an implicit cast:
ImplicitCastExpr 0x5145858 'uint64_t':'unsigned long' <IntegralCast>
`-BinaryOperator 0x5145830 'int' '*'
|-BinaryOperator 0x51457e8 'int' '*'
| |-IntegerLiteral 0x51457a8 'int' 4608
| `-IntegerLiteral 0x51457c8 'int' 1024
`-IntegerLiteral 0x5145810 'int' 1024
2) In Sema::CheckForIntOverflow, check for CallExprs and recursively check for
overflow on each argument.
This handles cases like f1(4096 * 1024 * 1024).
3) In IntExprEvaluator::VisitBinaryOperator(), bail out on AssignmentOps
_after_ running the DataRecursiveIntBinOpEvaluator. In fact, I am not sure
if check here for AssignmentOps is really necessary. It seems like it is an
early-exit optimization. Presumably it was thought that assignment
operators would not have any integer expression operands that need
evaluating here, however this is not the case in "x = y = 4096 * 1024 * 1024"
or "if ((y = 4096 * 1024 *1024))". Running the
DataRecursiveIntBinOpEvaluator
on AssignmentOps catches these cases. Note, this change was only needed to
catch these cases in C mode. In C++ mode an implicit LValueToRValue cast was
added which changed the path taken through semantic analysis.
Thanks,
Josh
http://llvm-reviews.chandlerc.com/D1238
Files:
lib/AST/ExprConstant.cpp
lib/Sema/SemaChecking.cpp
test/Sema/integer-overflow.c
test/SemaCXX/integer-overflow.cpp
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -6350,12 +6350,12 @@
}
bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
- if (E->isAssignmentOp())
- return Error(E);
-
if (DataRecursiveIntBinOpEvaluator::shouldEnqueue(E))
return DataRecursiveIntBinOpEvaluator(*this, Result).Traverse(E);
+ if (E->isAssignmentOp())
+ return Error(E);
+
QualType LHSTy = E->getLHS()->getType();
QualType RHSTy = E->getRHS()->getType();
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -5393,7 +5393,11 @@
/// 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())) {
+ if (CallExpr *CE = dyn_cast<CallExpr>(E->IgnoreParenCasts())) {
+ for (CallExpr::arg_iterator CEI = CE->arg_begin(),
+ CEE = CE->arg_end(); CEI != CEE; ++CEI)
+ CheckForIntOverflow(*CEI);
+ } else if (isa<BinaryOperator>(E->IgnoreParenCasts())) {
llvm::SmallVector<PartialDiagnosticAt, 4> Diags;
E->EvaluateForOverflow(Context, &Diags);
}
Index: test/Sema/integer-overflow.c
===================================================================
--- /dev/null
+++ test/Sema/integer-overflow.c
@@ -0,0 +1,175 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+typedef unsigned long long uint64_t;
+typedef unsigned long long uint32_t;
+
+uint64_t f0(uint64_t);
+uint64_t f1(uint64_t, uint32_t);
+uint64_t f2(uint64_t, ...);
+
+static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning {{overflow in expression; result is 536870912 with type 'int'}}
+
+uint64_t check_integer_overflows(int i) {
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ uint64_t overflow = 4608 * 1024 * 1024,
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow2 = (uint64_t)(4608 * 1024 * 1024),
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow3 = (uint64_t)(4608 * 1024 * 1024 * i),
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow4 = (1ULL * ((4608) * ((1024) * (1024))) + 2ULL),
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ multi_overflow = (uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow += overflow2 = overflow3 = (uint64_t)(4608 * 1024 * 1024);
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow += overflow2 = overflow3 = 4608 * 1024 * 1024;
+
+ uint64_t not_overflow = 4608 * 1024 * 1024ULL;
+ uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ overflow = 4608 * 1024 * 1024 ? 4608 * 1024 * 1024 : 0;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow = 0 ? 0 : 4608 * 1024 * 1024;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if (4608 * 1024 * 1024)
+ return 0;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if ((uint64_t)(4608 * 1024 * 1024))
+ return 1;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if ((uint64_t)(4608 * 1024 * 1024))
+ return 2;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if ((uint64_t)(4608 * 1024 * 1024 * i))
+ return 3;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL))
+ return 4;
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ if ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)))
+ return 5;
+
+ switch (i) {
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ case 4608 * 1024 * 1024:
+ return 6;
+// expected-warning@+1 {{overflow in expression; result is 537919488 with type 'int'}}
+ case (uint64_t)(4609 * 1024 * 1024):
+ return 7;
+// expected-error@+1 {{expression is not an integer constant expression}}
+ case ((uint64_t)(4608 * 1024 * 1024 * i)):
+ return 8;
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ case ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL)):
+ return 9;
+// expected-warning@+2 2{{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+1 {{overflow converting case value to switch condition type (288230376151711744 to 0)}}
+ case ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024))):
+ return 10;
+ }
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while (4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while ((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while ((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while ((uint64_t)(4608 * 1024 * 1024 * i));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ while ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while (4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((uint64_t)(4608 * 1024 * 1024 * i));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
+
+// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
+ for (uint64_t i = 4608 * 1024 * 1024;
+ (uint64_t)(4608 * 1024 * 1024);
+ i += (uint64_t)(4608 * 1024 * 1024 * i));
+
+// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+3 2{{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+3 2{{overflow in expression; result is 536870912 with type 'int'}}
+ for (uint64_t i = (1ULL * ((4608) * ((1024) * (1024))) + 2ULL);
+ ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
+ i = ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024))));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0((uint64_t)(4608 * 1024 * 1024 * i));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ f0((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0(overflow = 4608 * 1024 * 1024);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ f1((uint64_t)(4608 * 1024 * 1024), 4608 * 1024 * 1024);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ f1((uint64_t)(4608 * 1024 * 1024 * i), (1ULL * ((4608) * ((1024) * (1024))) + 2ULL));
+
+// expected-warning@+1 3{{overflow in expression; result is 536870912 with type 'int'}}
+ f1((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)), overflow = 4608 * 1024 * 1024);
+
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 2{{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+ f2(f1(f0((uint64_t)(4608 * 1024 * 1024)),
+ f0(4608 * 1024 * 1024)),
+ (uint64_t)(4608 * 1024 * 1024 * i),
+ (1ULL * ((4608) * ((1024) * (1024))) + 2ULL),
+ (uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)),
+ overflow = 4608 * 1024 * 1024);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
+}
Index: test/SemaCXX/integer-overflow.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/integer-overflow.cpp
@@ -0,0 +1,197 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -std=gnu++98
+typedef unsigned long long uint64_t;
+typedef unsigned long long uint32_t;
+
+uint64_t f0(uint64_t);
+uint64_t f1(uint64_t, uint32_t);
+uint64_t f2(uint64_t, ...);
+
+static const uint64_t overflow = 1 * 4608 * 1024 * 1024; // expected-warning {{overflow in expression; result is 536870912 with type 'int'}}
+
+uint64_t check_integer_overflows(int i) { //expected-note {{declared here}}
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ uint64_t overflow = 4608 * 1024 * 1024,
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow2 = (uint64_t)(4608 * 1024 * 1024),
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow3 = (uint64_t)(4608 * 1024 * 1024 * i),
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow4 = (1ULL * ((4608) * ((1024) * (1024))) + 2ULL),
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow5 = static_cast<uint64_t>(4608 * 1024 * 1024),
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ multi_overflow = (uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow += overflow2 = overflow3 = (uint64_t)(4608 * 1024 * 1024);
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow += overflow2 = overflow3 = 4608 * 1024 * 1024;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow += overflow2 = overflow3 = static_cast<uint64_t>(4608 * 1024 * 1024);
+
+ uint64_t not_overflow = 4608 * 1024 * 1024ULL;
+ uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ overflow = 4608 * 1024 * 1024 ? 4608 * 1024 * 1024 : 0;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ overflow = 0 ? 0 : 4608 * 1024 * 1024;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if (4608 * 1024 * 1024)
+ return 0;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if ((uint64_t)(4608 * 1024 * 1024))
+ return 1;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if (static_cast<uint64_t>(4608 * 1024 * 1024))
+ return 1;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if ((uint64_t)(4608 * 1024 * 1024))
+ return 2;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if ((uint64_t)(4608 * 1024 * 1024 * i))
+ return 3;
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ if ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL))
+ return 4;
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ if ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)))
+ return 5;
+
+ switch (i) {
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ case 4608 * 1024 * 1024:
+ return 6;
+// expected-warning@+1 {{overflow in expression; result is 537919488 with type 'int'}}
+ case (uint64_t)(4609 * 1024 * 1024):
+ return 7;
+// expected-warning@+1 {{overflow in expression; result is 537919488 with type 'int'}}
+ case 1 + static_cast<uint64_t>(4609 * 1024 * 1024):
+ return 7;
+// expected-error@+2 {{expression is not an integral constant expression}}
+// expected-note@+1 {{read of non-const variable 'i' is not allowed in a constant expression}}
+ case ((uint64_t)(4608 * 1024 * 1024 * i)):
+ return 8;
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ case ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL)):
+ return 9;
+// expected-warning@+2 2{{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+1 {{overflow converting case value to switch condition type (288230376151711744 to 0)}}
+ case ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024))):
+ return 10;
+ }
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while (4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while ((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while (static_cast<uint64_t>(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while ((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while ((uint64_t)(4608 * 1024 * 1024 * i));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ while ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ while ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while (4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while (static_cast<uint64_t>(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((uint64_t)(4608 * 1024 * 1024 * i));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ do { } while ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
+
+// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
+ for (uint64_t i = 4608 * 1024 * 1024;
+ (uint64_t)(4608 * 1024 * 1024);
+ i += (uint64_t)(4608 * 1024 * 1024 * i));
+
+// expected-warning@+3 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+3 2{{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+3 2{{overflow in expression; result is 536870912 with type 'int'}}
+ for (uint64_t i = (1ULL * ((4608) * ((1024) * (1024))) + 2ULL);
+ ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
+ i = ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024))));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0(4608 * 1024 * 1024);
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0(static_cast<uint64_t>(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0((uint64_t)(4608 * 1024 * 1024));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0((uint64_t)(4608 * 1024 * 1024 * i));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0((1ULL * ((4608) * ((1024) * (1024))) + 2ULL));
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ f0((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
+
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
+ f0(overflow = 4608 * 1024 * 1024);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ f1((uint64_t)(4608 * 1024 * 1024), 4608 * 1024 * 1024);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ f1((uint64_t)(4608 * 1024 * 1024 * i), (1ULL * ((4608) * ((1024) * (1024))) + 2ULL));
+
+// expected-warning@+1 3{{overflow in expression; result is 536870912 with type 'int'}}
+ f1((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)), overflow = 4608 * 1024 * 1024);
+
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 2{{overflow in expression; result is 536870912 with type 'int'}}
+// expected-warning@+6 {{overflow in expression; result is 536870912 with type 'int'}}
+ f2(f1(f0((uint64_t)(4608 * 1024 * 1024)),
+ f0(4608 * 1024 * 1024)),
+ (uint64_t)(4608 * 1024 * 1024 * i),
+ (1ULL * ((4608) * ((1024) * (1024))) + 2ULL),
+ (uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)),
+ overflow = 4608 * 1024 * 1024);
+
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
+ return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits