]> granicus.if.org Git - clang/commitdiff
In the expression evaluator, visit the index of an ArraySubscriptExpr even if we...
authorNick Lewycky <nicholas@mxc.ca>
Thu, 27 Apr 2017 07:27:36 +0000 (07:27 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Thu, 27 Apr 2017 07:27:36 +0000 (07:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301522 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/Sema/integer-overflow.c

index 5c5b3daf70cc712d536c7ce8692ac3462bdba910..2947b97bfcde4b75b744951c66f39bef4412094d 100644 (file)
@@ -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) {
index 12d2c4f29e0562bbdb928746c5490958aff1d1d7..44c2629ebf7bcb71f63b75a7028abfbd83682389 100644 (file)
@@ -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);