diff options
author | John McCall <rjmccall@apple.com> | 2012-03-10 03:05:10 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2012-03-10 03:05:10 +0000 |
commit | dd2ecee313b558a9b621ec003b45e0fbc83508d7 (patch) | |
tree | d071b135e22daff2be22ca0e14c4af47a4952820 /lib/CodeGen/CGExprScalar.cpp | |
parent | 89da8cf16b671845660711d3dd4174a809ca6cca (diff) |
Unify the BlockDeclRefExpr and DeclRefExpr paths so that
we correctly emit loads of BlockDeclRefExprs even when they
don't qualify as ODR-uses. I think I'm adequately convinced
that BlockDeclRefExpr can die.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152479 91177308-0d34-0410-b5e6-96231b3b80d8
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 //===----------------------------------------------------------------------===// |