aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprScalar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/CGExprScalar.cpp')
-rw-r--r--lib/CodeGen/CGExprScalar.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index 125e431bff..f7ab880e6c 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -212,18 +212,21 @@ public:
// l-values.
Value *VisitDeclRefExpr(DeclRefExpr *E) {
Expr::EvalResult Result;
- if (!E->EvaluateAsRValue(Result, CGF.getContext()))
- return EmitLoadOfLValue(E);
+ bool IsReferenceConstant = false;
+ QualType EvalTy = E->getType();
+ if (!E->EvaluateAsRValue(Result, CGF.getContext())) {
+ // If this is a reference, try to determine what it is bound to.
+ if (!E->getDecl()->getType()->isReferenceType() ||
+ !E->EvaluateAsLValue(Result, CGF.getContext()))
+ return EmitLoadOfLValue(E);
+
+ IsReferenceConstant = true;
+ EvalTy = E->getDecl()->getType();
+ }
assert(!Result.HasSideEffects && "Constant declref with side-effect?!");
- llvm::Constant *C;
- if (Result.Val.isInt())
- C = Builder.getInt(Result.Val.getInt());
- else if (Result.Val.isFloat())
- C = llvm::ConstantFP::get(VMContext, Result.Val.getFloat());
- else
- return EmitLoadOfLValue(E);
+ llvm::Constant *C = CGF.CGM.EmitConstantValue(Result.Val, EvalTy, &CGF);
// Make sure we emit a debug reference to the global variable.
if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) {
@@ -233,6 +236,9 @@ public:
CGF.EmitDeclRefExprDbgValue(E, C);
}
+ if (IsReferenceConstant)
+ return EmitLoadOfLValue(CGF.MakeNaturalAlignAddrLValue(C, E->getType()));
+
return C;
}
Value *VisitObjCSelectorExpr(ObjCSelectorExpr *E) {