r301522 - 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.
Nick Lewycky via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 27 00:27:37 PDT 2017
Author: nicholas
Date: Thu Apr 27 02:27:36 2017
New Revision: 301522
URL: http://llvm.org/viewvc/llvm-project?rev=301522&view=rev
Log:
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.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/integer-overflow.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=301522&r1=301521&r2=301522&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Apr 27 02:27:36 2017
@@ -5246,14 +5246,19 @@ bool LValueExprEvaluator::VisitArraySubs
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) {
Modified: cfe/trunk/test/Sema/integer-overflow.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/integer-overflow.c?rev=301522&r1=301521&r2=301522&view=diff
==============================================================================
--- cfe/trunk/test/Sema/integer-overflow.c (original)
+++ cfe/trunk/test/Sema/integer-overflow.c Thu Apr 27 02:27:36 2017
@@ -147,6 +147,10 @@ uint64_t check_integer_overflows(int i)
uint64_t a[10];
a[4608 * 1024 * 1024] = 1i;
+// expected-warning at +2 {{overflow in expression; result is 536870912 with type 'int'}}
+ uint64_t *b;
+ uint64_t b2 = b[4608 * 1024 * 1024] + 1;
+
// expected-warning at +1 2{{overflow in expression; result is 536870912 with type 'int'}}
(void)((i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024)) + 1);
More information about the cfe-commits
mailing list