diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2010-09-06 00:10:32 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2010-09-06 00:10:32 +0000 |
commit | a7dedf7004e8ac3f947d6817370b2778fa648c2b (patch) | |
tree | 9e7ce457c4f053adc6bde2efd180cadf2b251349 /lib/AST/ExprConstant.cpp | |
parent | 6d6370ee10ddcd8cacc44c2d6796800c1325c732 (diff) |
PR7242: Make sure to use a different context for evaluating constant
initializers, so the result of the evaluation doesn't leak through
inconsistently. Also, don't evaluate references to variables with
initializers with side-effects.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113128 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 175fd85a24..7347f5a43e 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -1008,8 +1008,11 @@ bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) { VD->setEvaluatingValue(); - if (Visit(const_cast<Expr*>(Init))) { + Expr::EvalResult EResult; + if (Init->Evaluate(EResult, Info.Ctx) && !EResult.HasSideEffects && + EResult.Val.isInt()) { // Cache the evaluated value in the variable declaration. + Result = EResult.Val; VD->setEvaluatedValue(Result); return true; } |