diff options
author | John McCall <rjmccall@apple.com> | 2012-03-10 09:33:50 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2012-03-10 09:33:50 +0000 |
commit | f4b88a45902af1802a1cb42ba48b1c474474f228 (patch) | |
tree | 7f613834b56ecad44c6a1a99d69d2230a034e7b6 /lib | |
parent | 1659c3758b4b2dbd618aed9ff8d1863f11b1bd9b (diff) |
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
Diffstat (limited to 'lib')
41 files changed, 263 insertions, 513 deletions
diff --git a/lib/ARCMigrate/TransAutoreleasePool.cpp b/lib/ARCMigrate/TransAutoreleasePool.cpp index 08561f97f9..87877242a1 100644 --- a/lib/ARCMigrate/TransAutoreleasePool.cpp +++ b/lib/ARCMigrate/TransAutoreleasePool.cpp @@ -263,10 +263,6 @@ private: return checkRef(E->getLocation(), E->getDecl()->getLocation()); } - bool VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { - return checkRef(E->getLocation(), E->getDecl()->getLocation()); - } - bool VisitTypedefTypeLoc(TypedefTypeLoc TL) { return checkRef(TL.getBeginLoc(), TL.getTypedefNameDecl()->getLocation()); } diff --git a/lib/ARCMigrate/TransBlockObjCVariable.cpp b/lib/ARCMigrate/TransBlockObjCVariable.cpp index 5f9592739d..845da159a1 100644 --- a/lib/ARCMigrate/TransBlockObjCVariable.cpp +++ b/lib/ARCMigrate/TransBlockObjCVariable.cpp @@ -48,8 +48,8 @@ class RootBlockObjCVarRewriter : BlockVarChecker(VarDecl *var) : Var(var) { } bool TraverseImplicitCastExpr(ImplicitCastExpr *castE) { - if (BlockDeclRefExpr * - ref = dyn_cast<BlockDeclRefExpr>(castE->getSubExpr())) { + if (DeclRefExpr * + ref = dyn_cast<DeclRefExpr>(castE->getSubExpr())) { if (ref->getDecl() == Var) { if (castE->getCastKind() == CK_LValueToRValue) return true; // Using the value of the variable. @@ -62,7 +62,7 @@ class RootBlockObjCVarRewriter : return base::TraverseImplicitCastExpr(castE); } - bool VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { + bool VisitDeclRefExpr(DeclRefExpr *E) { if (E->getDecl() == Var) return false; // The reference of the variable, and not just its value, // is needed. diff --git a/lib/ARCMigrate/Transforms.cpp b/lib/ARCMigrate/Transforms.cpp index 6d08d1e7d2..45a8c989ef 100644 --- a/lib/ARCMigrate/Transforms.cpp +++ b/lib/ARCMigrate/Transforms.cpp @@ -194,7 +194,6 @@ class ReferenceClear : public RecursiveASTVisitor<ReferenceClear> { public: ReferenceClear(ExprSet &refs) : Refs(refs) { } bool VisitDeclRefExpr(DeclRefExpr *E) { Refs.erase(E); return true; } - bool VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { Refs.erase(E); return true; } }; class ReferenceCollector : public RecursiveASTVisitor<ReferenceCollector> { @@ -210,12 +209,6 @@ public: Refs.insert(E); return true; } - - bool VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { - if (E->getDecl() == Dcl) - Refs.insert(E); - return true; - } }; class RemovablesCollector : public RecursiveASTVisitor<RemovablesCollector> { diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index cc0213fca2..febfaabd74 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -3947,6 +3947,7 @@ Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { Importer.Import(E->getQualifierLoc()), Importer.Import(E->getTemplateKeywordLoc()), ToD, + E->refersToEnclosingLocal(), Importer.Import(E->getLocation()), T, E->getValueKind(), FoundD, diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index af2927977d..dc16379554 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -173,7 +173,7 @@ static void GenerateInjectedTemplateArgs(ASTContext &Context, Arg = TemplateArgument(ArgType); } else if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*Param)) { - Expr *E = new (Context) DeclRefExpr(NTTP, + Expr *E = new (Context) DeclRefExpr(NTTP, /*enclosing*/ false, NTTP->getType().getNonLValueExprType(Context), Expr::getValueKindForType(NTTP->getType()), NTTP->getLocation()); diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 3264e4ce0e..6722e2f21c 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -263,7 +263,8 @@ void DeclRefExpr::computeDependence(ASTContext &Ctx) { DeclRefExpr::DeclRefExpr(ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, - ValueDecl *D, const DeclarationNameInfo &NameInfo, + ValueDecl *D, bool RefersToEnclosingLocal, + const DeclarationNameInfo &NameInfo, NamedDecl *FoundD, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK) @@ -277,6 +278,7 @@ DeclRefExpr::DeclRefExpr(ASTContext &Ctx, getInternalFoundDecl() = FoundD; DeclRefExprBits.HasTemplateKWAndArgsInfo = (TemplateArgs || TemplateKWLoc.isValid()) ? 1 : 0; + DeclRefExprBits.RefersToEnclosingLocal = RefersToEnclosingLocal; if (TemplateArgs) { bool Dependent = false; bool InstantiationDependent = false; @@ -299,12 +301,14 @@ DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, + bool RefersToEnclosingLocal, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD, const TemplateArgumentListInfo *TemplateArgs) { return Create(Context, QualifierLoc, TemplateKWLoc, D, + RefersToEnclosingLocal, DeclarationNameInfo(D->getDeclName(), NameLoc), T, VK, FoundD, TemplateArgs); } @@ -313,6 +317,7 @@ DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, + bool RefersToEnclosingLocal, const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK, @@ -334,6 +339,7 @@ DeclRefExpr *DeclRefExpr::Create(ASTContext &Context, void *Mem = Context.Allocate(Size, llvm::alignOf<DeclRefExpr>()); return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D, + RefersToEnclosingLocal, NameInfo, FoundD, TemplateArgs, T, VK); } @@ -1867,14 +1873,8 @@ bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { ->isOBJCGCCandidate(Ctx); case CStyleCastExprClass: return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx); - case BlockDeclRefExprClass: case DeclRefExprClass: { - - const Decl *D; - if (const BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E)) - D = BDRE->getDecl(); - else - D = cast<DeclRefExpr>(E)->getDecl(); + const Decl *D = cast<DeclRefExpr>(E)->getDecl(); if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { if (VD->hasGlobalStorage()) @@ -2194,7 +2194,6 @@ Expr::CanThrowResult Expr::CanThrow(ASTContext &C) const { case AsTypeExprClass: case BinaryConditionalOperatorClass: case BlockExprClass: - case BlockDeclRefExprClass: case CUDAKernelCallExprClass: case DeclRefExprClass: case ObjCBridgedCastExprClass: @@ -3664,24 +3663,6 @@ Stmt::child_range ObjCMessageExpr::children() { reinterpret_cast<Stmt **>(getArgs() + getNumArgs())); } -// Blocks -BlockDeclRefExpr::BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, - SourceLocation l, bool ByRef, - bool constAdded) - : Expr(BlockDeclRefExprClass, t, VK, OK_Ordinary, false, false, false, - d->isParameterPack()), - D(d), Loc(l), IsByRef(ByRef), ConstQualAdded(constAdded) -{ - bool TypeDependent = false; - bool ValueDependent = false; - bool InstantiationDependent = false; - computeDeclRefDependence(D->getASTContext(), D, getType(), TypeDependent, - ValueDependent, InstantiationDependent); - ExprBits.TypeDependent = TypeDependent; - ExprBits.ValueDependent = ValueDependent; - ExprBits.InstantiationDependent = InstantiationDependent; -} - ObjCArrayLiteral::ObjCArrayLiteral(llvm::ArrayRef<Expr *> Elements, QualType T, ObjCMethodDecl *Method, SourceRange SR) diff --git a/lib/AST/ExprClassification.cpp b/lib/AST/ExprClassification.cpp index 00160a0073..7c402c98e4 100644 --- a/lib/AST/ExprClassification.cpp +++ b/lib/AST/ExprClassification.cpp @@ -189,9 +189,6 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) { return isa<FunctionDecl>(cast<DeclRefExpr>(E)->getDecl()) ? Cl::CL_PRValue : Cl::CL_LValue; return ClassifyDecl(Ctx, cast<DeclRefExpr>(E)->getDecl()); - // We deal with names referenced from blocks the same way. - case Expr::BlockDeclRefExprClass: - return ClassifyDecl(Ctx, cast<BlockDeclRefExpr>(E)->getDecl()); // Member access is complex. case Expr::MemberExprClass: @@ -565,8 +562,11 @@ static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E, // it is not marked __block, e.g. // void takeclosure(void (^C)(void)); // void func() { int x = 1; takeclosure(^{ x = 7; }); } - if (const BlockDeclRefExpr *BDR = dyn_cast<BlockDeclRefExpr>(E)) { - if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl())) + if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) { + if (DRE->refersToEnclosingLocal() && + isa<VarDecl>(DRE->getDecl()) && + cast<VarDecl>(DRE->getDecl())->hasLocalStorage() && + !DRE->getDecl()->hasAttr<BlocksAttr>()) return Cl::CM_NotBlockQualified; } diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 97c906c407..2a2b6fb373 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -2284,11 +2284,6 @@ public: return true; return false; } - bool VisitBlockDeclRefExpr (const BlockDeclRefExpr *E) { - if (Ctx.getCanonicalType(E->getType()).isVolatileQualified()) - return true; - return false; - } // We don't want to evaluate BlockExprs multiple times, as they generate // a ton of code. @@ -6278,7 +6273,6 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { case Expr::ObjCIsaExprClass: case Expr::ShuffleVectorExprClass: case Expr::BlockExprClass: - case Expr::BlockDeclRefExprClass: case Expr::NoStmtClass: case Expr::OpaqueValueExprClass: case Expr::PackExpansionExprClass: diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index c4eed7c34d..fa78227778 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -2351,7 +2351,6 @@ recurse: // These all can only appear in local or variable-initialization // contexts and so should never appear in a mangling. case Expr::AddrLabelExprClass: - case Expr::BlockDeclRefExprClass: case Expr::CXXThisExprClass: case Expr::DesignatedInitExprClass: case Expr::ImplicitValueInitExprClass: diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index d5e53a69d4..1fe4a792da 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1816,10 +1816,6 @@ void StmtPrinter::VisitBlockExpr(BlockExpr *Node) { } } -void StmtPrinter::VisitBlockDeclRefExpr(BlockDeclRefExpr *Node) { - OS << *Node->getDecl(); -} - void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) { PrintExpr(Node->getSourceExpr()); } diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index db27f821f5..c999ed4526 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -460,13 +460,6 @@ void StmtProfiler::VisitBlockExpr(const BlockExpr *S) { VisitDecl(S->getBlockDecl()); } -void StmtProfiler::VisitBlockDeclRefExpr(const BlockDeclRefExpr *S) { - VisitExpr(S); - VisitDecl(S->getDecl()); - ID.AddBoolean(S->isByRef()); - ID.AddBoolean(S->isConstQualAdded()); -} - void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) { VisitExpr(S); for (unsigned i = 0; i != S->getNumAssocs(); ++i) { diff --git a/lib/Analysis/AnalysisDeclContext.cpp b/lib/Analysis/AnalysisDeclContext.cpp index cbb08fd3da..1020898e60 100644 --- a/lib/Analysis/AnalysisDeclContext.cpp +++ b/lib/Analysis/AnalysisDeclContext.cpp @@ -362,20 +362,16 @@ public: flag = 1; BEVals.push_back(VD, BC); } + } else if (DR->refersToEnclosingLocal()) { + unsigned &flag = Visited[VD]; + if (!flag) { + flag = 1; + if (IsTrackedDecl(VD)) + BEVals.push_back(VD, BC); + } } } - void VisitBlockDeclRefExpr(BlockDeclRefExpr *DR) { - if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) { - unsigned &flag = Visited[VD]; - if (!flag) { - flag = 1; - if (IsTrackedDecl(VD)) - BEVals.push_back(VD, BC); - } - } - } - void VisitBlockExpr(BlockExpr *BR) { // Blocks containing blocks can transitively capture more variables. IgnoredContexts.insert(BR->getBlockDecl()); diff --git a/lib/Analysis/PseudoConstantAnalysis.cpp b/lib/Analysis/PseudoConstantAnalysis.cpp index 8f24c432b1..c8b491a216 100644 --- a/lib/Analysis/PseudoConstantAnalysis.cpp +++ b/lib/Analysis/PseudoConstantAnalysis.cpp @@ -68,8 +68,6 @@ bool PseudoConstantAnalysis::wasReferenced(const VarDecl *VD) { const Decl *PseudoConstantAnalysis::getDecl(const Expr *E) { if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E)) return DR->getDecl(); - else if (const BlockDeclRefExpr *BDR = dyn_cast<BlockDeclRefExpr>(E)) - return BDR->getDecl(); else return 0; } @@ -198,18 +196,7 @@ void PseudoConstantAnalysis::RunAnalysis() { break; } - // Case 4: Block variable references - case Stmt::BlockDeclRefExprClass: { - const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(Head); - if (const VarDecl *VD = dyn_cast<VarDecl>(BDR->getDecl())) { - // Add the Decl to the used list - UsedVars->insert(VD); - continue; - } - break; - } - - // Case 5: Variable references + // Case 4: Variable references case Stmt::DeclRefExprClass: { const DeclRefExpr *DR = cast<DeclRefExpr>(Head); if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) { @@ -220,7 +207,7 @@ void PseudoConstantAnalysis::RunAnalysis() { break; } - // Case 6: Block expressions + // Case 5: Block expressions case Stmt::BlockExprClass: { const BlockExpr *B = cast<BlockExpr>(Head); // Add the body of the block to the list diff --git a/lib/Analysis/ThreadSafety.cpp b/lib/Analysis/ThreadSafety.cpp index b2f89cce6b..2f7e794c2b 100644 --- a/lib/Analysis/ThreadSafety.cpp +++ b/lib/Analysis/ThreadSafety.cpp @@ -1040,7 +1040,7 @@ void BuildLockset::addLocksToSet(LockKind LK, AttrType *Attr, addLock(Mutex, LockData(ExpLocation, LK)); if (isScopedVar) { // For scoped lockable vars, map this var to its underlying mutex. - DeclRefExpr DRE(VD, VD->getType(), VK_LValue, VD->getLocation()); + DeclRefExpr DRE(VD, false, VD->getType(), VK_LValue, VD->getLocation()); MutexID SMutex(&DRE, 0, 0); addLock(SMutex, LockData(VD->getLocation(), LK, Mutex)); } @@ -1656,7 +1656,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) { // Create a dummy expression, VarDecl *VD = const_cast<VarDecl*>(AD->getVarDecl()); - DeclRefExpr DRE(VD, VD->getType(), VK_LValue, + DeclRefExpr DRE(VD, false, VD->getType(), VK_LValue, AD->getTriggerStmt()->getLocEnd()); LocksetBuilder.handleCall(&DRE, DD); break; diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 1b35fa0ee4..8e280e6823 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -753,16 +753,12 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { // We use one of these or the other depending on whether the // reference is nested. - DeclRefExpr notNested(const_cast<VarDecl*>(variable), type, VK_LValue, - SourceLocation()); - BlockDeclRefExpr nested(const_cast<VarDecl*>(variable), type, - VK_LValue, SourceLocation(), /*byref*/ false); - - Expr *declRef = - (ci->isNested() ? static_cast<Expr*>(&nested) : ¬Nested); + DeclRefExpr declRef(const_cast<VarDecl*>(variable), + /*refersToEnclosing*/ ci->isNested(), type, + VK_LValue, SourceLocation()); ImplicitCastExpr l2r(ImplicitCastExpr::OnStack, type, CK_LValueToRValue, - declRef, VK_RValue); + &declRef, VK_RValue); EmitExprAsInit(&l2r, &blockFieldPseudoVar, MakeAddrLValue(blockField, type, getContext().getDeclAlign(variable)), @@ -1107,7 +1103,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, LocalDeclMap[variable] = alloca; } - // Save a spot to insert the debug information for all the BlockDeclRefDecls. + // Save a spot to insert the debug information for all the DeclRefExprs. llvm::BasicBlock *entry = Builder.GetInsertBlock(); llvm::BasicBlock::iterator entry_ptr = Builder.GetInsertPoint(); --entry_ptr; @@ -1124,7 +1120,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, ++entry_ptr; Builder.SetInsertPoint(entry, entry_ptr); - // Emit debug information for all the BlockDeclRefDecls. + // Emit debug information for all the DeclRefExprs. // FIXME: also for 'this' if (CGDebugInfo *DI = getDebugInfo()) { for (BlockDecl::capture_const_iterator ci = blockDecl->capture_begin(), diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 06a3343bc2..a3437f7458 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -394,8 +394,8 @@ namespace { void Emit(CodeGenFunction &CGF, Flags flags) { // Compute the address of the local variable, in case it's a // byref or something. - DeclRefExpr DRE(const_cast<VarDecl*>(&Var), Var.getType(), VK_LValue, - SourceLocation()); + DeclRefExpr DRE(const_cast<VarDecl*>(&Var), false, + Var.getType(), VK_LValue, SourceLocation()); llvm::Value *value = CGF.EmitLoadOfScalar(CGF.EmitDeclRefLValue(&DRE)); CGF.EmitExtendGCLifetime(value); } @@ -411,8 +411,8 @@ namespace { : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {} void Emit(CodeGenFunction &CGF, Flags flags) { - DeclRefExpr DRE(const_cast<VarDecl*>(&Var), Var.getType(), VK_LValue, - SourceLocation()); + DeclRefExpr DRE(const_cast<VarDecl*>(&Var), false, + Var.getType(), VK_LValue, SourceLocation()); // Compute the address of the local variable, in case it's a byref // or something. llvm::Value *Addr = CGF.EmitDeclRefLValue(&DRE).getAddress(); 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<InitListExpr>(E)->getInit(0)); - case Expr::BlockDeclRefExprClass: - return EmitBlockDeclRefLValue(cast<BlockDeclRefExpr>(E)); - case Expr::CXXTemporaryObjectExprClass: case Expr::CXXConstructExprClass: return EmitCXXConstructLValue(cast<CXXConstructExpr>(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<ParmVarDecl>(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<VarDecl>(value)) { if (!getContext().DeclMustBeEmitted(cast<VarDecl>(value))) - EmitDeclRefExprDbgValue(&stackRef, C); + EmitDeclRefExprDbgValue(refExpr, C); } else { assert(isa<EnumConstantDecl>(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<VarDecl>(ND)) { - // Check if this is a global variable. if (VD->hasExternalStorage() || VD->isFileVarDecl()) return EmitGlobalVarDeclLValue(*this, E, VD); + bool isBlockVariable = VD->hasAttr<BlocksAttr>(); + bool NonGCable = VD->hasLocalStorage() && !VD->getType()->isReferenceType() && - !VD->hasAttr<BlocksAttr>(); + !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<BlockDecl>(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<BlocksAttr>()) + 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) { - |