diff options
Diffstat (limited to 'lib/CodeGen/CGExprScalar.cpp')
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 61 |
1 files changed, 15 insertions, 46 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 9da493448a..a6ba79803d 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -211,48 +211,24 @@ public: // Otherwise, assume the mapping is the scalar directly. return CGF.getOpaqueRValueMapping(E).getScalarVal(); } - - // l-values. - Value *VisitDeclRefExpr(DeclRefExpr *E) { - VarDecl *VD = dyn_cast<VarDecl>(E->getDecl()); - if (!VD && !isa<EnumConstantDecl>(E->getDecl())) - return EmitLoadOfLValue(E); - if (VD && !VD->isUsableInConstantExpressions(CGF.getContext())) - return EmitLoadOfLValue(E); - // This is an enumerator or a variable which is usable in constant - // expressions. Try to emit its value instead. - Expr::EvalResult Result; - 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 = CGF.CGM.EmitConstantValue(Result.Val, EvalTy, &CGF); - - // Make sure we emit a debug reference to the global variable. - if (VD) { - if (!CGF.getContext().DeclMustBeEmitted(VD)) - CGF.EmitDeclRefExprDbgValue(E, C); - } else { - assert(isa<EnumConstantDecl>(E->getDecl())); - CGF.EmitDeclRefExprDbgValue(E, C); + // l-values. + Value *emitDeclRef(ValueDecl *VD, Expr *refExpr) { + if (CodeGenFunction::ConstantEmission result + = CGF.tryEmitAsConstant(VD, refExpr)) { + if (result.isReference()) + return EmitLoadOfLValue(result.getReferenceLValue(CGF, refExpr)); + return result.getValue(); } - - if (IsReferenceConstant) - return EmitLoadOfLValue(CGF.MakeNaturalAlignAddrLValue(C, E->getType())); - - return C; + return EmitLoadOfLValue(refExpr); + } + Value *VisitDeclRefExpr(DeclRefExpr *E) { + return emitDeclRef(E->getDecl(), E); } + Value *VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { + return emitDeclRef(E->getDecl(), E); + } + Value *VisitObjCSelectorExpr(ObjCSelectorExpr *E) { return CGF.EmitObjCSelectorExpr(E); } @@ -304,8 +280,6 @@ public: Value *VisitStmtExpr(const StmtExpr *E); - Value *VisitBlockDeclRefExpr(const BlockDeclRefExpr *E); - // Unary Operators. Value *VisitUnaryPostDec(const UnaryOperator *E) { LValue LV = EmitLValue(E->getSubExpr()); @@ -1272,11 +1246,6 @@ Value *ScalarExprEmitter::VisitStmtExpr(const StmtExpr *E) { .getScalarVal(); } -Value *ScalarExprEmitter::VisitBlockDeclRefExpr(const BlockDeclRefExpr *E) { - LValue LV = CGF.EmitBlockDeclRefLValue(E); - return CGF.EmitLoadOfLValue(LV).getScalarVal(); -} - //===----------------------------------------------------------------------===// // Unary Operators //===----------------------------------------------------------------------===// |