diff options
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 15 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 18 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/references.cpp | 1 | 
3 files changed, 16 insertions, 18 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7651884aa60..d0d8b81bab0 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -178,11 +178,20 @@ static bool EvaluateLValue(const Expr* E, APValue& Result, EvalInfo &Info) {  }  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) diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 0df03ec3a27..b30bafb5105 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -478,21 +478,9 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *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) { diff --git a/clang/test/CodeGenCXX/references.cpp b/clang/test/CodeGenCXX/references.cpp index 5d4ac06c5bb..9d5a2ed9eef 100644 --- a/clang/test/CodeGenCXX/references.cpp +++ b/clang/test/CodeGenCXX/references.cpp @@ -11,6 +11,7 @@ void t2(int& a) {  int g;  int& gr = g; +int& grr = gr;  void t3() {    int b = gr;  }  | 

