}
APValue LValueExprEvaluator::VisitDeclRefExpr(DeclRefExpr *E)
-{
+{
if (!E->hasGlobalStorage())
return APValue();
-
- return APValue(E, 0);
+
+ if (isa<FunctionDecl>(E->getDecl())) {
+ return APValue(E, 0);
+ } else if (VarDecl* VD = dyn_cast<VarDecl>(E->getDecl())) {
+ if (!VD->getType()->isReferenceType())
+ return APValue(E, 0);
+ if (VD->getInit())
+ return Visit(VD->getInit());
+ }
+
+ return APValue();
}
APValue LValueExprEvaluator::VisitBlockExpr(BlockExpr *E)
bool Success = false;
- if (DestType->isReferenceType()) {
- // If the destination type is a reference type, we need to evaluate it
- // as an lvalue.
- if (E->EvaluateAsLValue(Result, Context)) {
- if (const Expr *LVBase = Result.Val.getLValueBase()) {
- if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(LVBase)) {
- const ValueDecl *VD = cast<ValueDecl>(DRE->getDecl());
-
- // We can only initialize a reference with an lvalue if the lvalue
- // is not a reference itself.
- Success = !VD->getType()->isReferenceType();
- }
- }
- }
- } else
+ if (DestType->isReferenceType())
+ Success = E->EvaluateAsLValue(Result, Context);
+ else
Success = E->Evaluate(Result, Context);
if (Success) {