aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-09-13 10:17:44 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-09-13 10:17:44 +0000
commitb2f295c8050fb8c141bf2cf38eed0a56e99d0092 (patch)
tree656693630861fa328565505d3bde850a858c4753 /lib/AST/ExprConstant.cpp
parent98303b93ae335bbb4731f6f1f8164d3c70648346 (diff)
Add utility to evaluate lvalues which are an offset relative to a stack
location. Patch by Enea Zaffanella. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81672 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 4494896d2c..8f5ff7284b 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -46,8 +46,12 @@ struct EvalInfo {
/// EvalResult - Contains information about the evaluation.
Expr::EvalResult &EvalResult;
- EvalInfo(ASTContext &ctx, Expr::EvalResult& evalresult) : Ctx(ctx),
- EvalResult(evalresult) {}
+ /// AnyLValue - Stack based LValue results are not discarded.
+ bool AnyLValue;
+
+ EvalInfo(ASTContext &ctx, Expr::EvalResult& evalresult,
+ bool anylvalue = false)
+ : Ctx(ctx), EvalResult(evalresult), AnyLValue(anylvalue) {}
};
@@ -189,7 +193,7 @@ APValue LValueExprEvaluator::VisitDeclRefExpr(DeclRefExpr *E) {
if (isa<FunctionDecl>(E->getDecl())) {
return APValue(E, 0);
} else if (VarDecl* VD = dyn_cast<VarDecl>(E->getDecl())) {
- if (!VD->hasGlobalStorage())
+ if (!Info.AnyLValue && !VD->hasGlobalStorage())
return APValue();
if (!VD->getType()->isReferenceType())
return APValue(E, 0);
@@ -209,9 +213,9 @@ APValue LValueExprEvaluator::VisitBlockExpr(BlockExpr *E) {
}
APValue LValueExprEvaluator::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
- if (E->isFileScope())
- return APValue(E, 0);
- return APValue();
+ if (!Info.AnyLValue && !E->isFileScope())
+ return APValue();
+ return APValue(E, 0);
}
APValue LValueExprEvaluator::VisitMemberExpr(MemberExpr *E) {
@@ -1786,6 +1790,12 @@ bool Expr::EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const {
return EvaluateLValue(this, Result.Val, Info) && !Result.HasSideEffects;
}
+bool Expr::EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const {
+ EvalInfo Info(Ctx, Result, true);
+
+ return EvaluateLValue(this, Result.Val, Info) && !Result.HasSideEffects;
+}
+
/// isEvaluatable - Call Evaluate to see if this expression can be constant
/// folded, but discard the result.
bool Expr::isEvaluatable(ASTContext &Ctx) const {