From f4b88a45902af1802a1cb42ba48b1c474474f228 Mon Sep 17 00:00:00 2001 From: John McCall Date: Sat, 10 Mar 2012 09:33:50 +0000 Subject: Remove BlockDeclRefExpr and introduce a bit on DeclRefExpr to track whether the referenced declaration comes from an enclosing local context. I'm amenable to suggestions about the exact meaning of this bit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152491 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExpr.cpp | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'lib/CodeGen/CGExpr.cpp') diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 3275327c9b..80233b5d28 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -679,9 +679,6 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) { "Only single-element init list can be lvalue."); return EmitLValue(cast(E)->getInit(0)); - case Expr::BlockDeclRefExprClass: - return EmitBlockDeclRefLValue(cast(E)); - case Expr::CXXTemporaryObjectExprClass: case Expr::CXXConstructExprClass: return EmitCXXConstructLValue(cast(E)); @@ -796,7 +793,9 @@ static ConstantEmissionKind checkVarTypeForConstantEmission(QualType type) { /// in a block or lambda, which means const int variables or constexpr /// literals or similar. CodeGenFunction::ConstantEmission -CodeGenFunction::tryEmitAsConstant(ValueDecl *value, Expr *refExpr) { +CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) { + ValueDecl *value = refExpr->getDecl(); + // The value needs to be an enum constant or a constant variable. ConstantEmissionKind CEK; if (isa(value)) { @@ -810,25 +809,19 @@ CodeGenFunction::tryEmitAsConstant(ValueDecl *value, Expr *refExpr) { } if (CEK == CEK_None) return ConstantEmission(); - // We evaluate use an on-stack DeclRefExpr because the constant - // evaluator (quite reasonably) ignores BlockDeclRefExprs. - DeclRefExpr stackRef(value, refExpr->getType(), refExpr->getValueKind(), - refExpr->getExprLoc()); - - // If it's okay to evaluate as a Expr::EvalResult result; bool resultIsReference; QualType resultType; // It's best to evaluate all the way as an r-value if that's permitted. if (CEK != CEK_AsReferenceOnly && - stackRef.EvaluateAsRValue(result, getContext())) { + refExpr->EvaluateAsRValue(result, getContext())) { resultIsReference = false; resultType = refExpr->getType(); // Otherwise, try to evaluate as an l-value. } else if (CEK != CEK_AsValueOnly && - stackRef.EvaluateAsLValue(result, getContext())) { + refExpr->EvaluateAsLValue(result, getContext())) { resultIsReference = true; resultType = value->getType(); @@ -848,10 +841,10 @@ CodeGenFunction::tryEmitAsConstant(ValueDecl *value, Expr *refExpr) { // This should probably fire even for if (isa(value)) { if (!getContext().DeclMustBeEmitted(cast(value))) - EmitDeclRefExprDbgValue(&stackRef, C); + EmitDeclRefExprDbgValue(refExpr, C); } else { assert(isa(value)); - EmitDeclRefExprDbgValue(&stackRef, C); + EmitDeclRefExprDbgValue(refExpr, C); } // If we emitted a reference constant, we need to dereference that. @@ -1499,27 +1492,34 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { } if (const VarDecl *VD = dyn_cast(ND)) { - // Check if this is a global variable. if (VD->hasExternalStorage() || VD->isFileVarDecl()) return EmitGlobalVarDeclLValue(*this, E, VD); + bool isBlockVariable = VD->hasAttr(); + bool NonGCable = VD->hasLocalStorage() && !VD->getType()->isReferenceType() && - !VD->hasAttr(); + !isBlockVariable; llvm::Value *V = LocalDeclMap[VD]; if (!V && VD->isStaticLocal()) V = CGM.getStaticLocalDeclAddress(VD); // Use special handling for lambdas. - if (!V) + if (!V) { if (FieldDecl *FD = LambdaCaptureFields.lookup(VD)) return EmitLValueForField(CXXABIThisValue, FD, 0); + assert(isa(CurCodeDecl) && E->refersToEnclosingLocal()); + CharUnits alignment = getContext().getDeclAlign(VD); + return MakeAddrLValue(GetAddrOfBlockDecl(VD, isBlockVariable), + E->getType(), alignment); + } + assert(V && "DeclRefExpr not entered in LocalDeclMap?"); - if (VD->hasAttr()) + if (isBlockVariable) V = BuildBlockByrefAddress(V, VD); LValue LV; @@ -1546,11 +1546,6 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { llvm_unreachable("Unhandled DeclRefExpr"); } -LValue CodeGenFunction::EmitBlockDeclRefLValue(const BlockDeclRefExpr *E) { - CharUnits Alignment = getContext().getDeclAlign(E->getDecl()); - return MakeAddrLValue(GetAddrOfBlockDecl(E), E->getType(), Alignment); -} - LValue CodeGenFunction::EmitUnaryOpLValue(const UnaryOperator *E) { // __extension__ doesn't affect lvalue-ness. if (E->getOpcode() == UO_Extension) -- cgit v1.2.3-70-g09d2