summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2017-04-27 07:27:36 +0000
committerNick Lewycky <nicholas@mxc.ca>2017-04-27 07:27:36 +0000
commitad8886896e5316ff913b8c684df1cfc2910f5973 (patch)
tree760a20167c50d42349dd66cb8b2107b8260aa632
parent7b0ec39494d8e1ef67d9788231cf7fe250406af5 (diff)
downloadbcm5719-llvm-ad8886896e5316ff913b8c684df1cfc2910f5973.tar.gz
bcm5719-llvm-ad8886896e5316ff913b8c684df1cfc2910f5973.zip
In the expression evaluator, visit the index of an ArraySubscriptExpr even if we can't evaluate the base, if the evaluation mode tells us to continue evaluation.
llvm-svn: 301522
-rw-r--r--clang/lib/AST/ExprConstant.cpp11
-rw-r--r--clang/test/Sema/integer-overflow.c4
2 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5c5b3daf70c..2947b97bfcd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -5246,14 +5246,19 @@ bool LValueExprEvaluator::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
if (E->getBase()->getType()->isVectorType())
return Error(E);
- if (!evaluatePointer(E->getBase(), Result))
- return false;
+ bool Success = true;
+ if (!evaluatePointer(E->getBase(), Result)) {
+ if (!Info.noteFailure())
+ return false;
+ Success = false;
+ }
APSInt Index;
if (!EvaluateInteger(E->getIdx(), Index, Info))
return false;
- return HandleLValueArrayAdjustment(Info, E, Result, E->getType(), Index);
+ return Success &&
+ HandleLValueArrayAdjustment(Info, E, Result, E->getType(), Index);
}
bool LValueExprEvaluator::VisitUnaryDeref(const UnaryOperator *E) {
diff --git a/clang/test/Sema/integer-overflow.c b/clang/test/Sema/integer-overflow.c
index 12d2c4f29e0..44c2629ebf7 100644
--- a/clang/test/Sema/integer-overflow.c
+++ b/clang/test/Sema/integer-overflow.c
@@ -147,6 +147,10 @@ uint64_t check_integer_overflows(int i) {
uint64_t a[10];
a[4608 * 1024 * 1024] = 1i;
+// expected-warning@+2 {{overflow in expression; result is 536870912 with type 'int'}}
+ uint64_t *b;
+ uint64_t b2 = b[4608 * 1024 * 1024] + 1;
+
// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
(void)((i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024)) + 1);
OpenPOWER on IntegriCloud