From 113bee05361d648adb51edd0e2ec281432d2009f Mon Sep 17 00:00:00 2001 From: John McCall Date: Sat, 10 Mar 2012 09:33:50 +0000 Subject: [PATCH] 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. llvm-svn: 152491 --- clang/include/clang/AST/Expr.h | 58 ++----- clang/include/clang/AST/RecursiveASTVisitor.h | 1 - clang/include/clang/AST/Stmt.h | 1 + clang/include/clang/Basic/StmtNodes.td | 1 - clang/include/clang/Sema/Sema.h | 1 - .../include/clang/Serialization/ASTBitCodes.h | 2 - clang/lib/ARCMigrate/TransAutoreleasePool.cpp | 4 - .../lib/ARCMigrate/TransBlockObjCVariable.cpp | 6 +- clang/lib/ARCMigrate/Transforms.cpp | 7 - clang/lib/AST/ASTImporter.cpp | 1 + clang/lib/AST/DeclTemplate.cpp | 2 +- clang/lib/AST/Expr.cpp | 35 +--- clang/lib/AST/ExprClassification.cpp | 10 +- clang/lib/AST/ExprConstant.cpp | 6 - clang/lib/AST/ItaniumMangle.cpp | 1 - clang/lib/AST/StmtPrinter.cpp | 4 - clang/lib/AST/StmtProfile.cpp | 7 - clang/lib/Analysis/AnalysisDeclContext.cpp | 18 +-- clang/lib/Analysis/PseudoConstantAnalysis.cpp | 17 +- clang/lib/Analysis/ThreadSafety.cpp | 4 +- clang/lib/CodeGen/CGBlocks.cpp | 16 +- clang/lib/CodeGen/CGDecl.cpp | 8 +- clang/lib/CodeGen/CGExpr.cpp | 41 +++-- clang/lib/CodeGen/CGExprAgg.cpp | 14 +- clang/lib/CodeGen/CGExprComplex.cpp | 15 +- clang/lib/CodeGen/CGExprScalar.cpp | 15 +- clang/lib/CodeGen/CGObjC.cpp | 60 ++++--- clang/lib/CodeGen/CodeGenFunction.h | 9 +- clang/lib/Rewrite/RewriteModernObjC.cpp | 149 ++++++++---------- clang/lib/Rewrite/RewriteObjC.cpp | 132 +++++++--------- clang/lib/Sema/SemaChecking.cpp | 12 +- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/lib/Sema/SemaDeclCXX.cpp | 4 +- clang/lib/Sema/SemaExpr.cpp | 74 ++------- clang/lib/Sema/SemaExprCXX.cpp | 1 + clang/lib/Sema/SemaInit.cpp | 11 +- clang/lib/Sema/SemaObjCProperty.cpp | 6 +- clang/lib/Sema/SemaOverload.cpp | 6 +- clang/lib/Sema/SemaTemplateVariadic.cpp | 9 -- clang/lib/Sema/TreeTransform.h | 26 +-- clang/lib/Serialization/ASTReaderStmt.cpp | 15 +- clang/lib/Serialization/ASTWriter.cpp | 1 - clang/lib/Serialization/ASTWriterDecl.cpp | 1 + clang/lib/Serialization/ASTWriterStmt.cpp | 10 +- .../Checkers/IdempotentOperationChecker.cpp | 1 - .../Checkers/UndefCapturedBlockVarChecker.cpp | 8 +- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 8 - clang/tools/libclang/CIndex.cpp | 4 - clang/tools/libclang/CXCursor.cpp | 1 - 49 files changed, 280 insertions(+), 565 deletions(-) diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index f28a9bed0a30..294112bc3a63 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -766,6 +766,9 @@ public: /// DeclRefExprBits.HasTemplateKWAndArgsInfo: /// Specifies when this declaration reference expression has an explicit /// C++ template keyword and/or template argument list. +/// DeclRefExprBits.RefersToEnclosingLocal +/// Specifies when this declaration reference expression (validly) +/// refers to a local variable from a different function. class DeclRefExpr : public Expr { /// \brief The declaration that we are referencing. ValueDecl *D; @@ -810,7 +813,8 @@ class DeclRefExpr : public Expr { 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); @@ -824,7 +828,8 @@ class DeclRefExpr : public Expr { void computeDependence(ASTContext &C); public: - DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L, + DeclRefExpr(ValueDecl *D, bool refersToEnclosingLocal, QualType T, + ExprValueKind VK, SourceLocation L, const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), D(D), Loc(L), DNLoc(LocInfo) { @@ -832,6 +837,7 @@ public: DeclRefExprBits.HasTemplateKWAndArgsInfo = 0; DeclRefExprBits.HasFoundDecl = 0; DeclRefExprBits.HadMultipleCandidates = 0; + DeclRefExprBits.RefersToEnclosingLocal = refersToEnclosingLocal; computeDependence(D->getASTContext()); } @@ -839,6 +845,7 @@ public: NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, + bool isEnclosingLocal, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD = 0, @@ -848,6 +855,7 @@ public: NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, + bool isEnclosingLocal, const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK, NamedDecl *FoundD = 0, @@ -1023,6 +1031,12 @@ public: DeclRefExprBits.HadMultipleCandidates = V; } + /// Does this DeclRefExpr refer to a local declaration from an + /// enclosing function scope? + bool refersToEnclosingLocal() const { + return DeclRefExprBits.RefersToEnclosingLocal; + } + static bool classof(const Stmt *T) { return T->getStmtClass() == DeclRefExprClass; } @@ -4275,46 +4289,6 @@ public: child_range children() { return child_range(); } }; -/// BlockDeclRefExpr - A reference to a local variable declared in an -/// enclosing scope. -class BlockDeclRefExpr : public Expr { - VarDecl *D; - SourceLocation Loc; - bool IsByRef : 1; - bool ConstQualAdded : 1; -public: - BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, - SourceLocation l, bool ByRef, bool constAdded = false); - - // \brief Build an empty reference to a declared variable in a - // block. - explicit BlockDeclRefExpr(EmptyShell Empty) - : Expr(BlockDeclRefExprClass, Empty) { } - - VarDecl *getDecl() { return D; } - const VarDecl *getDecl() const { return D; } - void setDecl(VarDecl *VD) { D = VD; } - - SourceLocation getLocation() const { return Loc; } - void setLocation(SourceLocation L) { Loc = L; } - - SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } - - bool isByRef() const { return IsByRef; } - void setByRef(bool BR) { IsByRef = BR; } - - bool isConstQualAdded() const { return ConstQualAdded; } - void setConstQualAdded(bool C) { ConstQualAdded = C; } - - static bool classof(const Stmt *T) { - return T->getStmtClass() == BlockDeclRefExprClass; - } - static bool classof(const BlockDeclRefExpr *) { return true; } - - // Iterators - child_range children() { return child_range(); } -}; - /// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] /// This AST node provides support for reinterpreting a type to another /// type of the same size. diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 38a6a8515abe..f3dcf71f5f89 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2015,7 +2015,6 @@ DEF_TRAVERSE_STMT(CXXMemberCallExpr, { }) // over the children. DEF_TRAVERSE_STMT(AddrLabelExpr, { }) DEF_TRAVERSE_STMT(ArraySubscriptExpr, { }) -DEF_TRAVERSE_STMT(BlockDeclRefExpr, { }) DEF_TRAVERSE_STMT(BlockExpr, { TRY_TO(TraverseDecl(S->getBlockDecl())); return true; // no child statements to loop through. diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index 2e2fd84ba6e4..84bdfb89cac2 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -194,6 +194,7 @@ protected: unsigned HasTemplateKWAndArgsInfo : 1; unsigned HasFoundDecl : 1; unsigned HadMultipleCandidates : 1; + unsigned RefersToEnclosingLocal : 1; }; class CastExprBitfields { diff --git a/clang/include/clang/Basic/StmtNodes.td b/clang/include/clang/Basic/StmtNodes.td index 8d2e8f53a6fe..67d71e44c0a4 100644 --- a/clang/include/clang/Basic/StmtNodes.td +++ b/clang/include/clang/Basic/StmtNodes.td @@ -156,7 +156,6 @@ def CUDAKernelCallExpr : DStmt; // Clang Extensions. def ShuffleVectorExpr : DStmt; def BlockExpr : DStmt; -def BlockDeclRefExpr : DStmt; def OpaqueValueExpr : DStmt; // Microsoft Extensions. diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 86634d128c08..245cfb077707 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2419,7 +2419,6 @@ public: void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D); void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func); void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); - void MarkBlockDeclRefReferenced(BlockDeclRefExpr *E); void MarkDeclRefReferenced(DeclRefExpr *E); void MarkMemberReferenced(MemberExpr *E); diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index a25851e0d583..4591630357dd 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -1052,8 +1052,6 @@ namespace clang { EXPR_SHUFFLE_VECTOR, /// \brief BlockExpr EXPR_BLOCK, - /// \brief A BlockDeclRef record. - EXPR_BLOCK_DECL_REF, /// \brief A GenericSelectionExpr record. EXPR_GENERIC_SELECTION, /// \brief A PseudoObjectExpr record. diff --git a/clang/lib/ARCMigrate/TransAutoreleasePool.cpp b/clang/lib/ARCMigrate/TransAutoreleasePool.cpp index 08561f97f962..87877242a124 100644 --- a/clang/lib/ARCMigrate/TransAutoreleasePool.cpp +++ b/clang/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/clang/lib/ARCMigrate/TransBlockObjCVariable.cpp b/clang/lib/ARCMigrate/TransBlockObjCVariable.cpp index 5f9592739d56..845da159a13a 100644 --- a/clang/lib/ARCMigrate/TransBlockObjCVariable.cpp +++ b/clang/lib/ARCMigrate/TransBlockObjCVariable.cpp @@ -48,8 +48,8 @@ class RootBlockObjCVarRewriter : BlockVarChecker(VarDecl *var) : Var(var) { } bool TraverseImplicitCastExpr(ImplicitCastExpr *castE) { - if (BlockDeclRefExpr * - ref = dyn_cast(castE->getSubExpr())) { + if (DeclRefExpr * + ref = dyn_cast(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/clang/lib/ARCMigrate/Transforms.cpp b/clang/lib/ARCMigrate/Transforms.cpp index 6d08d1e7d2b0..45a8c989efd3 100644 --- a/clang/lib/ARCMigrate/Transforms.cpp +++ b/clang/lib/ARCMigrate/Transforms.cpp @@ -194,7 +194,6 @@ class ReferenceClear : public RecursiveASTVisitor { 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 { @@ -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 { diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index cc0213fca235..febfaabd7401 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/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/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index af2927977d22..dc16379554a5 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -173,7 +173,7 @@ static void GenerateInjectedTemplateArgs(ASTContext &Context, Arg = TemplateArgument(ArgType); } else if (NonTypeTemplateParmDecl *NTTP = dyn_cast(*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/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 3264e4ce0e24..6722e2f21c78 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/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()); 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(E)->getSubExpr()->isOBJCGCCandidate(Ctx); - case BlockDeclRefExprClass: case DeclRefExprClass: { - - const Decl *D; - if (const BlockDeclRefExpr *BDRE = dyn_cast(E)) - D = BDRE->getDecl(); - else - D = cast(E)->getDecl(); + const Decl *D = cast(E)->getDecl(); if (const VarDecl *VD = dyn_cast(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(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 Elements, QualType T, ObjCMethodDecl *Method, SourceRange SR) diff --git a/clang/lib/AST/ExprClassification.cpp b/clang/lib/AST/ExprClassification.cpp index 00160a007379..7c402c98e41a 100644 --- a/clang/lib/AST/ExprClassification.cpp +++ b/clang/lib/AST/ExprClassification.cpp @@ -189,9 +189,6 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) { return isa(cast(E)->getDecl()) ? Cl::CL_PRValue : Cl::CL_LValue; return ClassifyDecl(Ctx, cast(E)->getDecl()); - // We deal with names referenced from blocks the same way. - case Expr::BlockDeclRefExprClass: - return ClassifyDecl(Ctx, cast(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(E)) { - if (!BDR->isByRef() && isa(BDR->getDecl())) + if (const DeclRefExpr *DRE = dyn_cast(E)) { + if (DRE->refersToEnclosingLocal() && + isa(DRE->getDecl()) && + cast(DRE->getDecl())->hasLocalStorage() && + !DRE->getDecl()->hasAttr()) return Cl::CM_NotBlockQualified; } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 97c906c407f9..2a2b6fb37363 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index c4eed7c34d62..fa7822777891 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/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/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index d5e53a69d44a..1fe4a792dab0 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/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/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index db27f821f5b2..c999ed452605 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/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/clang/lib/Analysis/AnalysisDeclContext.cpp b/clang/lib/Analysis/AnalysisDeclContext.cpp index cbb08fd3da69..1020898e60cb 100644 --- a/clang/lib/Analysis/AnalysisDeclContext.cpp +++ b/clang/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(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/clang/lib/Analysis/PseudoConstantAnalysis.cpp b/clang/lib/Analysis/PseudoConstantAnalysis.cpp index 8f24c432b157..c8b491a21682 100644 --- a/clang/lib/Analysis/PseudoConstantAnalysis.cpp +++ b/clang/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(E)) return DR->getDecl(); - else if (const BlockDeclRefExpr *BDR = dyn_cast(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(Head); - if (const VarDecl *VD = dyn_cast(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(Head); if (const VarDecl *VD = dyn_cast(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(Head); // Add the body of the block to the list diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index b2f89cce6be1..2f7e794c2b38 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/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(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/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index 1b35fa0ee4de..8e280e6823e9 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/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(variable), type, VK_LValue, - SourceLocation()); - BlockDeclRefExpr nested(const_cast(variable), type, - VK_LValue, SourceLocation(), /*byref*/ false); - - Expr *declRef = - (ci->isNested() ? static_cast(&nested) : ¬Nested); + DeclRefExpr declRef(const_cast(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/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 06a3343bc259..a3437f7458a6 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/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(&Var), Var.getType(), VK_LValue, - SourceLocation()); + DeclRefExpr DRE(const_cast(&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(&Var), Var.getType(), VK_LValue, - SourceLocation()); + DeclRefExpr DRE(const_cast(&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/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 3275327c9be7..80233b5d2818 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/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) diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index f7c640adacf5..3e8ae06f166c 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -109,26 +109,22 @@ public: } // l-values. - void emitDeclRef(ValueDecl *VD, Expr *refExpr) { + void VisitDeclRefExpr(DeclRefExpr *E) { // For aggregates, we should always be able to emit the variable // as an l-value unless it's a reference. This is due to the fact // that we can't actually ever see a normal l2r conversion on an // aggregate in C++, and in C there's no language standard // actively preventing us from listing variables in the captures // list of a block. - if (VD->getType()->isReferenceType()) { + if (E->getDecl()->getType()->isReferenceType()) { if (CodeGenFunction::ConstantEmission result - = CGF.tryEmitAsConstant(VD, refExpr)) { - EmitFinalDestCopy(refExpr, result.getReferenceLValue(CGF, refExpr)); + = CGF.tryEmitAsConstant(E)) { + EmitFinalDestCopy(E, result.getReferenceLValue(CGF, E)); return; } } - EmitAggLoadOfLValue(refExpr); - } - void VisitDeclRefExpr(DeclRefExpr *E) { emitDeclRef(E->getDecl(), E); } - void VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { - emitDeclRef(E->getDecl(), E); + EmitAggLoadOfLValue(E); } void VisitMemberExpr(MemberExpr *ME) { EmitAggLoadOfLValue(ME); } diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index 7be88440ff08..c5b705f329cd 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -111,23 +111,16 @@ public: } // l-values. - ComplexPairTy emitDeclRef(ValueDecl *VD, Expr *refExpr) { - if (CodeGenFunction::ConstantEmission result - = CGF.tryEmitAsConstant(VD, refExpr)) { + ComplexPairTy VisitDeclRefExpr(DeclRefExpr *E) { + if (CodeGenFunction::ConstantEmission result = CGF.tryEmitAsConstant(E)) { if (result.isReference()) - return EmitLoadOfLValue(result.getReferenceLValue(CGF, refExpr)); + return EmitLoadOfLValue(result.getReferenceLValue(CGF, E)); llvm::ConstantStruct *pair = cast(result.getValue()); return ComplexPairTy(pair->getOperand(0), pair->getOperand(1)); } - return EmitLoadOfLValue(refExpr); - } - ComplexPairTy VisitDeclRefExpr(DeclRefExpr *E) { - return emitDeclRef(E->getDecl(), E); - } - ComplexPairTy VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { - return emitDeclRef(E->getDecl(), E); + return EmitLoadOfLValue(E); } ComplexPairTy VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { return EmitLoadOfLValue(E); diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index a6ba79803d44..d3cbf00c85c7 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -213,20 +213,13 @@ public: } // l-values. - Value *emitDeclRef(ValueDecl *VD, Expr *refExpr) { - if (CodeGenFunction::ConstantEmission result - = CGF.tryEmitAsConstant(VD, refExpr)) { + Value *VisitDeclRefExpr(DeclRefExpr *E) { + if (CodeGenFunction::ConstantEmission result = CGF.tryEmitAsConstant(E)) { if (result.isReference()) - return EmitLoadOfLValue(result.getReferenceLValue(CGF, refExpr)); + return EmitLoadOfLValue(result.getReferenceLValue(CGF, E)); return result.getValue(); } - return EmitLoadOfLValue(refExpr); - } - Value *VisitDeclRefExpr(DeclRefExpr *E) { - return emitDeclRef(E->getDecl(), E); - } - Value *VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { - return emitDeclRef(E->getDecl(), E); + return EmitLoadOfLValue(E); } Value *VisitObjCSelectorExpr(ObjCSelectorExpr *E) { diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index 6ece9e82b34f..059260144687 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -931,7 +931,7 @@ static void emitStructSetterCall(CodeGenFunction &CGF, ObjCMethodDecl *OMD, // The second argument is the address of the parameter variable. ParmVarDecl *argVar = *OMD->param_begin(); - DeclRefExpr argRef(argVar, argVar->getType().getNonReferenceType(), + DeclRefExpr argRef(argVar, false, argVar->getType().getNonReferenceType(), VK_LValue, SourceLocation()); llvm::Value *argAddr = CGF.EmitLValue(&argRef).getAddress(); argAddr = CGF.Builder.CreateBitCast(argAddr, CGF.Int8PtrTy); @@ -976,7 +976,7 @@ static void emitCPPObjectAtomicSetterCall(CodeGenFunction &CGF, // The second argument is the address of the parameter variable. ParmVarDecl *argVar = *OMD->param_begin(); - DeclRefExpr argRef(argVar, argVar->getType().getNonReferenceType(), + DeclRefExpr argRef(argVar, false, argVar->getType().getNonReferenceType(), VK_LValue, SourceLocation()); llvm::Value *argAddr = CGF.EmitLValue(&argRef).getAddress(); argAddr = CGF.Builder.CreateBitCast(argAddr, CGF.Int8PtrTy); @@ -1163,7 +1163,8 @@ CodeGenFunction::generateObjCSetterBody(const ObjCImplementationDecl *classImpl, // Otherwise, fake up some ASTs and emit a normal assignment. ValueDecl *selfDecl = setterMethod->getSelfDecl(); - DeclRefExpr self(selfDecl, selfDecl->getType(), VK_LValue, SourceLocation()); + DeclRefExpr self(selfDecl, false, selfDecl->getType(), + VK_LValue, SourceLocation()); ImplicitCastExpr selfLoad(ImplicitCastExpr::OnStack, selfDecl->getType(), CK_LValueToRValue, &self, VK_RValue); @@ -1172,7 +1173,7 @@ CodeGenFunction::generateObjCSetterBody(const ObjCImplementationDecl *classImpl, ParmVarDecl *argDecl = *setterMethod->param_begin(); QualType argType = argDecl->getType().getNonReferenceType(); - DeclRefExpr arg(argDecl, argType, VK_LValue, SourceLocation()); + DeclRefExpr arg(argDecl, false, argType, VK_LValue, SourceLocation()); ImplicitCastExpr argLoad(ImplicitCastExpr::OnStack, argType.getUnqualifiedType(), CK_LValueToRValue, &arg, VK_RValue); @@ -1525,7 +1526,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ EmitAutoVarInit(variable); const VarDecl* D = cast(SD->getSingleDecl()); - DeclRefExpr tempDRE(const_cast(D), D->getType(), + DeclRefExpr tempDRE(const_cast(D), false, D->getType(), VK_LValue, SourceLocation()); elementLValue = EmitLValue(&tempDRE); elementType = D->getType(); @@ -2817,28 +2818,23 @@ CodeGenFunction::GenerateObjCAtomicSetterCopyHelperFunction( StartFunction(FD, C.VoidTy, Fn, FI, args, SourceLocation()); - DeclRefExpr *DstExpr = - new (C) DeclRefExpr(&dstDecl, DestTy, - VK_RValue, SourceLocation()); + DeclRefExpr DstExpr(&dstDecl, false, DestTy, + VK_RValue, SourceLocation()); + UnaryOperator DST(&DstExpr, UO_Deref, DestTy->getPointeeType(), + VK_LValue, OK_Ordinary, SourceLocation()); - Expr* DST = new (C) UnaryOperator(DstExpr, UO_Deref, DestTy->getPointeeType(), - VK_LValue, OK_Ordinary, SourceLocation()); + DeclRefExpr SrcExpr(&srcDecl, false, SrcTy, + VK_RValue, SourceLocation()); + UnaryOperator SRC(&SrcExpr, UO_Deref, SrcTy->getPointeeType(), + VK_LValue, OK_Ordinary, SourceLocation()); - DeclRefExpr *SrcExpr = - new (C) DeclRefExpr(&srcDecl, SrcTy, - VK_RValue, SourceLocation()); - - Expr* SRC = new (C) UnaryOperator(SrcExpr, UO_Deref, SrcTy->getPointeeType(), - VK_LValue, OK_Ordinary, SourceLocation()); - - Expr *Args[2] = { DST, SRC }; + Expr *Args[2] = { &DST, &SRC }; CallExpr *CalleeExp = cast(PID->getSetterCXXAssignment()); - CXXOperatorCallExpr *TheCall = - new (C) CXXOperatorCallExpr(C, OO_Equal, CalleeExp->getCallee(), - Args, 2, DestTy->getPointeeType(), - VK_LValue, SourceLocation()); - - EmitStmt(TheCall); + CXXOperatorCallExpr TheCall(C, OO_Equal, CalleeExp->getCallee(), + Args, 2, DestTy->getPointeeType(), + VK_LValue, SourceLocation()); + + EmitStmt(&TheCall); FinishFunction(); HelperFn = llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy); @@ -2907,18 +2903,17 @@ CodeGenFunction::GenerateObjCAtomicGetterCopyHelperFunction( StartFunction(FD, C.VoidTy, Fn, FI, args, SourceLocation()); - DeclRefExpr *SrcExpr = - new (C) DeclRefExpr(&srcDecl, SrcTy, + DeclRefExpr SrcExpr(&srcDecl, false, SrcTy, VK_RValue, SourceLocation()); - Expr* SRC = new (C) UnaryOperator(SrcExpr, UO_Deref, SrcTy->getPointeeType(), - VK_LValue, OK_Ordinary, SourceLocation()); + UnaryOperator SRC(&SrcExpr, UO_Deref, SrcTy->getPointeeType(), + VK_LValue, OK_Ordinary, SourceLocation()); CXXConstructExpr *CXXConstExpr = cast(PID->getGetterCXXConstructor()); SmallVector ConstructorArgs; - ConstructorArgs.push_back(SRC); + ConstructorArgs.push_back(&SRC); CXXConstructExpr::arg_iterator A = CXXConstExpr->arg_begin(); ++A; @@ -2936,11 +2931,10 @@ CodeGenFunction::GenerateObjCAtomicGetterCopyHelperFunction( CXXConstExpr->requiresZeroInitialization(), CXXConstExpr->getConstructionKind(), SourceRange()); - DeclRefExpr *DstExpr = - new (C) DeclRefExpr(&dstDecl, DestTy, - VK_RValue, SourceLocation()); + DeclRefExpr DstExpr(&dstDecl, false, DestTy, + VK_RValue, SourceLocation()); - RValue DV = EmitAnyExpr(DstExpr); + RValue DV = EmitAnyExpr(&DstExpr); CharUnits Alignment = getContext().getTypeAlignInChars(TheCXXConstructExpr->getType()); EmitAggExpr(TheCXXConstructExpr, AggValueSlot::forAddr(DV.getScalarVal(), Alignment, Qualifiers(), diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index aeeb18c2a791..4be5beb46451 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1359,10 +1359,7 @@ public: } void AllocateBlockCXXThisPointer(const CXXThisExpr *E); - void AllocateBlockDecl(const BlockDeclRefExpr *E); - llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E) { - return GetAddrOfBlockDecl(E->getDecl(), E->isByRef()); - } + void AllocateBlockDecl(const DeclRefExpr *E); llvm::Value *GetAddrOfBlockDecl(const VarDecl *var, bool ByRef); llvm::Type *BuildByRefType(const VarDecl *var); @@ -2135,7 +2132,7 @@ public: } }; - ConstantEmission tryEmitAsConstant(ValueDecl *VD, Expr *refExpr); + ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr); RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot = AggValueSlot::ignored()); @@ -2163,8 +2160,6 @@ public: LValue EmitLValueForBitfield(llvm::Value* Base, const FieldDecl* Field, unsigned CVRQualifiers); - LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E); - LValue EmitCXXConstructLValue(const CXXConstructExpr *E); LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); LValue EmitLambdaLValue(const LambdaExpr *E); diff --git a/clang/lib/Rewrite/RewriteModernObjC.cpp b/clang/lib/Rewrite/RewriteModernObjC.cpp index 3e6a19c9fb29..3099499805d2 100644 --- a/clang/lib/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Rewrite/RewriteModernObjC.cpp @@ -120,9 +120,9 @@ namespace { // Block expressions. SmallVector Blocks; SmallVector InnerDeclRefsCount; - SmallVector InnerDeclRefs; + SmallVector InnerDeclRefs; - SmallVector BlockDeclRefs; + SmallVector BlockDeclRefs; // Block related declarations. SmallVector BlockByCopyDecls; @@ -327,7 +327,7 @@ namespace { // Block specific rewrite rules. void RewriteBlockPointerDecl(NamedDecl *VD); void RewriteByRefVar(VarDecl *VD); - Stmt *RewriteBlockDeclRefExpr(Expr *VD); + Stmt *RewriteBlockDeclRefExpr(DeclRefExpr *VD); Stmt *RewriteLocalVariableExternalStorage(DeclRefExpr *DRE); void RewriteBlockPointerFunctionArgs(FunctionDecl *FD); @@ -407,7 +407,7 @@ namespace { StringRef FunName); FunctionDecl *SynthBlockInitFunctionDecl(StringRef name); Stmt *SynthBlockInitExpr(BlockExpr *Exp, - const SmallVector &InnerBlockDeclRefs); + const SmallVector &InnerBlockDeclRefs); // Misc. helper routines. QualType getProtocolType(); @@ -421,7 +421,7 @@ namespace { void CollectBlockDeclRefInfo(BlockExpr *Exp); void GetBlockDeclRefExprs(Stmt *S); void GetInnerBlockDeclRefExprs(Stmt *S, - SmallVector &InnerBlockDeclRefs, + SmallVector &InnerBlockDeclRefs, llvm::SmallPtrSet &InnerContexts); // We avoid calling Type::isBlockPointerType(), since it operates on the @@ -2062,7 +2062,7 @@ CallExpr *RewriteModernObjC::SynthesizeCallToFunctionDecl( // Create a reference to the objc_msgSend() declaration. DeclRefExpr *DRE = - new (Context) DeclRefExpr(FD, msgSendType, VK_LValue, SourceLocation()); + new (Context) DeclRefExpr(FD, false, msgSendType, VK_LValue, SourceLocation()); // Now, we cast the reference to a pointer to the objc_msgSend type. QualType pToFunc = Context->getPointerType(msgSendType); @@ -2575,7 +2575,7 @@ Stmt *RewriteModernObjC::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) { VarDecl *NewVD = VarDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(S), strType, 0, SC_Static, SC_None); - DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, strType, VK_LValue, + DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, false, strType, VK_LValue, SourceLocation()); Expr *Unop = new (Context) UnaryOperator(DRE, UO_AddrOf, Context->getPointerType(DRE->getType()), @@ -2703,6 +2703,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), CK_BitCast, new (Context) DeclRefExpr(CurMethodDef->getSelfDecl(), + false, Context->getObjCIdType(), VK_RValue, SourceLocation())) @@ -2744,7 +2745,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, SynthSuperContructorFunctionDecl(); // Simulate a contructor call... DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, - superType, VK_LValue, + false, superType, VK_LValue, SourceLocation()); SuperRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], InitExprs.size(), @@ -2814,6 +2815,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), CK_BitCast, new (Context) DeclRefExpr(CurMethodDef->getSelfDecl(), + false, Context->getObjCIdType(), VK_RValue, SourceLocation())) ); // set the 'receiver'. @@ -2853,7 +2855,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, SynthSuperContructorFunctionDecl(); // Simulate a contructor call... DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, - superType, VK_LValue, + false, superType, VK_LValue, SourceLocation()); SuperRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], InitExprs.size(), @@ -3005,7 +3007,7 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, QualType msgSendType = MsgSendFlavor->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, msgSendType, + DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); // Need to cast objc_msgSend to "void *" (to workaround a GCC bandaid). @@ -3041,7 +3043,8 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, // method's return type. // Create a reference to the objc_msgSend_stret() declaration. - DeclRefExpr *STDRE = new (Context) DeclRefExpr(MsgSendStretFlavor, msgSendType, + DeclRefExpr *STDRE = new (Context) DeclRefExpr(MsgSendStretFlavor, + false, msgSendType, VK_LValue, SourceLocation()); // Need to cast objc_msgSend_stret to "void *" (see above comment). cast = NoTypeInfoCStyleCastExpr(Context, @@ -3129,8 +3132,8 @@ Stmt *RewriteModernObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) { VarDecl *VD = VarDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), ID, getProtocolType(), 0, SC_Extern, SC_None); - DeclRefExpr *DRE = new (Context) DeclRefExpr(VD, getProtocolType(), VK_LValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr(VD, false, getProtocolType(), + VK_LValue, SourceLocation()); Expr *DerefExpr = new (Context) UnaryOperator(DRE, UO_AddrOf, Context->getPointerType(DRE->getType()), VK_RValue, OK_Ordinary, SourceLocation()); @@ -3689,21 +3692,25 @@ void RewriteModernObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, // Need to copy-in the inner copied-in variables not actually used in this // block. for (int j = 0; j < InnerDeclRefsCount[i]; j++) { - BlockDeclRefExpr *Exp = InnerDeclRefs[count++]; + DeclRefExpr *Exp = InnerDeclRefs[count++]; ValueDecl *VD = Exp->getDecl(); BlockDeclRefs.push_back(Exp); - if (!Exp->isByRef() && !BlockByCopyDeclsPtrSet.count(VD)) { - BlockByCopyDeclsPtrSet.insert(VD); - BlockByCopyDecls.push_back(VD); + if (!VD->hasAttr()) { + if (!BlockByCopyDeclsPtrSet.count(VD)) { + BlockByCopyDeclsPtrSet.insert(VD); + BlockByCopyDecls.push_back(VD); + } + continue; } - if (Exp->isByRef() && !BlockByRefDeclsPtrSet.count(VD)) { + + if (!BlockByRefDeclsPtrSet.count(VD)) { BlockByRefDeclsPtrSet.insert(VD); BlockByRefDecls.push_back(VD); } + // imported objects in the inner blocks not used in the outer // blocks must be copied/disposed in the outer block as well. - if (Exp->isByRef() || - VD->getType()->isObjCObjectPointerType() || + if (VD->getType()->isObjCObjectPointerType() || VD->getType()->isBlockPointerType()) ImportedBlockDecls.insert(VD); } @@ -3791,25 +3798,17 @@ void RewriteModernObjC::GetBlockDeclRefExprs(Stmt *S) { GetBlockDeclRefExprs(*CI); } // Handle specific things. - if (BlockDeclRefExpr *CDRE = dyn_cast(S)) { - // FIXME: Handle enums. - if (!isa(CDRE->getDecl())) - BlockDeclRefs.push_back(CDRE); - } - else if (DeclRefExpr *DRE = dyn_cast(S)) - if (HasLocalVariableExternalStorage(DRE->getDecl())) { - BlockDeclRefExpr *BDRE = - new (Context)BlockDeclRefExpr(cast(DRE->getDecl()), - DRE->getType(), - VK_LValue, DRE->getLocation(), false); - BlockDeclRefs.push_back(BDRE); + if (DeclRefExpr *DRE = dyn_cast(S)) + if (DRE->refersToEnclosingLocal() && + HasLocalVariableExternalStorage(DRE->getDecl())) { + BlockDeclRefs.push_back(DRE); } return; } void RewriteModernObjC::GetInnerBlockDeclRefExprs(Stmt *S, - SmallVector &InnerBlockDeclRefs, + SmallVector &InnerBlockDeclRefs, llvm::SmallPtrSet &InnerContexts) { for (Stmt::child_range CI = S->children(); CI; ++CI) if (*CI) { @@ -3826,15 +3825,15 @@ void RewriteModernObjC::GetInnerBlockDeclRefExprs(Stmt *S, } // Handle specific things. - if (BlockDeclRefExpr *CDRE = dyn_cast(S)) { - if (!isa(CDRE->getDecl()) && - !InnerContexts.count(CDRE->getDecl()->getDeclContext())) - InnerBlockDeclRefs.push_back(CDRE); - } - else if (DeclRefExpr *DRE = dyn_cast(S)) { - if (VarDecl *Var = dyn_cast(DRE->getDecl())) - if (Var->isFunctionOrMethodVarDecl()) - ImportedLocalExternalDecls.insert(Var); + if (DeclRefExpr *DRE = dyn_cast(S)) { + if (DRE->refersToEnclosingLocal()) { + if (!isa(DRE->getDecl()) && + !InnerContexts.count(DRE->getDecl()->getDeclContext())) + InnerBlockDeclRefs.push_back(DRE); + if (VarDecl *Var = dyn_cast(DRE->getDecl())) + if (Var->isFunctionOrMethodVarDecl()) + ImportedLocalExternalDecls.insert(Var); + } } return; @@ -3896,9 +3895,6 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp if (const DeclRefExpr *DRE = dyn_cast(BlockExp)) { CPT = DRE->getType()->getAs(); - } else if (const BlockDeclRefExpr *CDRE = - dyn_cast(BlockExp)) { - CPT = CDRE->getType()->getAs(); } else if (const MemberExpr *MExpr = dyn_cast(BlockExp)) { CPT = MExpr->getType()->getAs(); } @@ -3999,7 +3995,7 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp } // We need to return the rewritten expression to handle cases where the -// BlockDeclRefExpr is embedded in another expression being rewritten. +// DeclRefExpr is embedded in another expression being rewritten. // For example: // // int main() { @@ -4007,21 +4003,15 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp // __block int i; // // void (^myblock)() = ^() { -// [f test]; // f is a BlockDeclRefExpr embedded in a message (which is being rewritten). +// [f test]; // f is a DeclRefExpr embedded in a message (which is being rewritten). // i = 77; // }; //} -Stmt *RewriteModernObjC::RewriteBlockDeclRefExpr(Expr *DeclRefExp) { +Stmt *RewriteModernObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { // Rewrite the byref variable into BYREFVAR->__forwarding->BYREFVAR // for each DeclRefExp where BYREFVAR is name of the variable. - ValueDecl *VD; - bool isArrow = true; - if (BlockDeclRefExpr *BDRE = dyn_cast(DeclRefExp)) - VD = BDRE->getDecl(); - else { - VD = cast(DeclRefExp)->getDecl(); - isArrow = false; - } + ValueDecl *VD = DeclRefExp->getDecl(); + bool isArrow = DeclRefExp->refersToEnclosingLocal(); FieldDecl *FD = FieldDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), @@ -4515,7 +4505,7 @@ void RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { if (BlockDeclRefs.size()) { // Unique all "by copy" declarations. for (unsigned i = 0; i < BlockDeclRefs.size(); i++) - if (!BlockDeclRefs[i]->isByRef()) { + if (!BlockDeclRefs[i]->getDecl()->hasAttr()) { if (!BlockByCopyDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) { BlockByCopyDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl()); BlockByCopyDecls.push_back(BlockDeclRefs[i]->getDecl()); @@ -4523,7 +4513,7 @@ void RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { } // Unique all "by ref" declarations. for (unsigned i = 0; i < BlockDeclRefs.size(); i++) - if (BlockDeclRefs[i]->isByRef()) { + if (BlockDeclRefs[i]->getDecl()->hasAttr()) { if (!BlockByRefDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) { BlockByRefDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl()); BlockByRefDecls.push_back(BlockDeclRefs[i]->getDecl()); @@ -4531,7 +4521,7 @@ void RewriteModernObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { } // Find any imported blocks...they will need special attention. for (unsigned i = 0; i < BlockDeclRefs.size(); i++) - if (BlockDeclRefs[i]->isByRef() || + if (BlockDeclRefs[i]->getDecl()->hasAttr() || BlockDeclRefs[i]->getType()->isObjCObjectPointerType() || BlockDeclRefs[i]->getType()->isBlockPointerType()) ImportedBlockDecls.insert(BlockDeclRefs[i]->getDecl()); @@ -4547,7 +4537,7 @@ FunctionDecl *RewriteModernObjC::SynthBlockInitFunctionDecl(StringRef name) { } Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, - const SmallVector &InnerBlockDeclRefs) { + const SmallVector &InnerBlockDeclRefs) { const BlockDecl *block = Exp->getBlockDecl(); Blocks.push_back(Exp); @@ -4557,9 +4547,9 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, int countOfInnerDecls = 0; if (!InnerBlockDeclRefs.empty()) { for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) { - BlockDeclRefExpr *Exp = InnerBlockDeclRefs[i]; + DeclRefExpr *Exp = InnerBlockDeclRefs[i]; ValueDecl *VD = Exp->getDecl(); - if (!Exp->isByRef() && !BlockByCopyDeclsPtrSet.count(VD)) { + if (!VD->hasAttr() && !BlockByCopyDeclsPtrSet.count(VD)) { // We need to save the copied-in variables in nested // blocks because it is needed at the end for some of the API generations. // See SynthesizeBlockLiterals routine. @@ -4568,7 +4558,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, BlockByCopyDeclsPtrSet.insert(VD); BlockByCopyDecls.push_back(VD); } - if (Exp->isByRef() && !BlockByRefDeclsPtrSet.count(VD)) { + if (VD->hasAttr() && !BlockByRefDeclsPtrSet.count(VD)) { InnerDeclRefs.push_back(Exp); countOfInnerDecls++; BlockDeclRefs.push_back(Exp); BlockByRefDeclsPtrSet.insert(VD); @@ -4577,7 +4567,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, } // Find any imported blocks...they will need special attention. for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) - if (InnerBlockDeclRefs[i]->isByRef() || + if (InnerBlockDeclRefs[i]->getDecl()->hasAttr() || InnerBlockDeclRefs[i]->getType()->isObjCObjectPointerType() || InnerBlockDeclRefs[i]->getType()->isBlockPointerType()) ImportedBlockDecls.insert(InnerBlockDeclRefs[i]->getDecl()); @@ -4607,15 +4597,15 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, // Simulate a contructor call... FD = SynthBlockInitFunctionDecl(Tag); - DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, FType, VK_RValue, + DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, FType, VK_RValue, SourceLocation()); SmallVector InitExprs; // Initialize the block function. FD = SynthBlockInitFunctionDecl(Func); - DeclRefExpr *Arg = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, - SourceLocation()); + DeclRefExpr *Arg = new (Context) DeclRefExpr(FD, false, FD->getType(), + VK_LValue, SourceLocation()); CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, CK_BitCast, Arg); InitExprs.push_back(castExpr); @@ -4629,7 +4619,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, Context->VoidPtrTy, 0, SC_Static, SC_None); UnaryOperator *DescRefExpr = - new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, + new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, false, Context->VoidPtrTy, VK_LValue, SourceLocation()), @@ -4648,8 +4638,8 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, if (isObjCType((*I)->getType())) { // FIXME: Conform to ABI ([[obj retain] autorelease]). FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, - SourceLocation()); + Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), + VK_LValue, SourceLocation()); if (HasLocalVariableExternalStorage(*I)) { QualType QT = (*I)->getType(); QT = Context->getPointerType(QT); @@ -4658,14 +4648,14 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, } } else if (isTopLevelBlockPointerType((*I)->getType())) { FD = SynthBlockInitFunctionDecl((*I)->getName()); - Arg = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, - SourceLocation()); + Arg = new (Context) DeclRefExpr(FD, false, FD->getType(), + VK_LValue, SourceLocation()); Exp = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, CK_BitCast, Arg); } else { FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, - SourceLocation()); + Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), + VK_LValue, SourceLocation()); if (HasLocalVariableExternalStorage(*I)) { QualType QT = (*I)->getType(); QT = Context->getPointerType(QT); @@ -4692,7 +4682,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, + Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, SourceLocation()); bool isNestedCapturedVar = false; if (block) @@ -4786,7 +4776,7 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { } if (BlockExpr *BE = dyn_cast(S)) { - SmallVector InnerBlockDeclRefs; + SmallVector InnerBlockDeclRefs; llvm::SmallPtrSet InnerContexts; InnerContexts.insert(BE->getBlockDecl()); ImportedLocalExternalDecls.clear(); @@ -4931,10 +4921,6 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { Stmts.pop_back(); } // Handle blocks rewriting. - if (BlockDeclRefExpr *BDRE = dyn_cast(S)) { - if (BDRE->isByRef()) - return RewriteBlockDeclRefExpr(BDRE); - } if (DeclRefExpr *DRE = dyn_cast(S)) { ValueDecl *VD = DRE->getDecl(); if (VD->hasAttr()) @@ -6551,7 +6537,8 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { VarDecl *NewVD = VarDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(IvarOffsetName), Context->UnsignedLongTy, 0, SC_Extern, SC_None); - DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, Context->UnsignedLongTy, VK_LValue, + DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, false, + Context->UnsignedLongTy, VK_LValue, SourceLocation()); BinaryOperator *addExpr = new (Context) BinaryOperator(castExpr, DRE, BO_Add, diff --git a/clang/lib/Rewrite/RewriteObjC.cpp b/clang/lib/Rewrite/RewriteObjC.cpp index 6e8789f6dbc8..b317a2fb4dc5 100644 --- a/clang/lib/Rewrite/RewriteObjC.cpp +++ b/clang/lib/Rewrite/RewriteObjC.cpp @@ -119,9 +119,9 @@ namespace { // Block expressions. SmallVector Blocks; SmallVector InnerDeclRefsCount; - SmallVector InnerDeclRefs; + SmallVector InnerDeclRefs; - SmallVector BlockDeclRefs; + SmallVector BlockDeclRefs; // Block related declarations. SmallVector BlockByCopyDecls; @@ -320,7 +320,7 @@ namespace { // Block specific rewrite rules. void RewriteBlockPointerDecl(NamedDecl *VD); void RewriteByRefVar(VarDecl *VD); - Stmt *RewriteBlockDeclRefExpr(Expr *VD); + Stmt *RewriteBlockDeclRefExpr(DeclRefExpr *VD); Stmt *RewriteLocalVariableExternalStorage(DeclRefExpr *DRE); void RewriteBlockPointerFunctionArgs(FunctionDecl *FD); @@ -388,7 +388,7 @@ namespace { StringRef FunName); FunctionDecl *SynthBlockInitFunctionDecl(StringRef name); Stmt *SynthBlockInitExpr(BlockExpr *Exp, - const SmallVector &InnerBlockDeclRefs); + const SmallVector &InnerBlockDeclRefs); // Misc. helper routines. QualType getProtocolType(); @@ -402,7 +402,7 @@ namespace { void CollectBlockDeclRefInfo(BlockExpr *Exp); void GetBlockDeclRefExprs(Stmt *S); void GetInnerBlockDeclRefExprs(Stmt *S, - SmallVector &InnerBlockDeclRefs, + SmallVector &InnerBlockDeclRefs, llvm::SmallPtrSet &InnerContexts); // We avoid calling Type::isBlockPointerType(), since it operates on the @@ -2045,8 +2045,8 @@ CallExpr *RewriteObjC::SynthesizeCallToFunctionDecl( QualType msgSendType = FD->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = - new (Context) DeclRefExpr(FD, msgSendType, VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, msgSendType, + VK_LValue, SourceLocation()); // Now, we cast the reference to a pointer to the objc_msgSend type. QualType pToFunc = Context->getPointerType(msgSendType); @@ -2559,7 +2559,7 @@ Stmt *RewriteObjC::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) { VarDecl *NewVD = VarDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), &Context->Idents.get(S), strType, 0, SC_Static, SC_None); - DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, strType, VK_LValue, + DeclRefExpr *DRE = new (Context) DeclRefExpr(NewVD, false, strType, VK_LValue, SourceLocation()); Expr *Unop = new (Context) UnaryOperator(DRE, UO_AddrOf, Context->getPointerType(DRE->getType()), @@ -2687,6 +2687,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), CK_BitCast, new (Context) DeclRefExpr(CurMethodDef->getSelfDecl(), + false, Context->getObjCIdType(), VK_RValue, SourceLocation())) @@ -2728,7 +2729,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, SynthSuperContructorFunctionDecl(); // Simulate a contructor call... DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, - superType, VK_LValue, + false, superType, VK_LValue, SourceLocation()); SuperRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], InitExprs.size(), @@ -2798,6 +2799,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, NoTypeInfoCStyleCastExpr(Context, Context->getObjCIdType(), CK_BitCast, new (Context) DeclRefExpr(CurMethodDef->getSelfDecl(), + false, Context->getObjCIdType(), VK_RValue, SourceLocation())) ); // set the 'receiver'. @@ -2837,7 +2839,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, SynthSuperContructorFunctionDecl(); // Simulate a contructor call... DeclRefExpr *DRE = new (Context) DeclRefExpr(SuperContructorFunctionDecl, - superType, VK_LValue, + false, superType, VK_LValue, SourceLocation()); SuperRep = new (Context) CallExpr(*Context, DRE, &InitExprs[0], InitExprs.size(), @@ -2989,7 +2991,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, QualType msgSendType = MsgSendFlavor->getType(); // Create a reference to the objc_msgSend() declaration. - DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, msgSendType, + DeclRefExpr *DRE = new (Context) DeclRefExpr(MsgSendFlavor, false, msgSendType, VK_LValue, SourceLocation()); // Need to cast objc_msgSend to "void *" (to workaround a GCC bandaid). @@ -3025,7 +3027,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, // method's return type. // Create a reference to the objc_msgSend_stret() declaration. - DeclRefExpr *STDRE = new (Context) DeclRefExpr(MsgSendStretFlavor, msgSendType, + DeclRefExpr *STDRE = new (Context) DeclRefExpr(MsgSendStretFlavor, + false, msgSendType, VK_LValue, SourceLocation()); // Need to cast objc_msgSend_stret to "void *" (see above comment). cast = NoTypeInfoCStyleCastExpr(Context, @@ -3113,8 +3116,8 @@ Stmt *RewriteObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) { VarDecl *VD = VarDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), ID, getProtocolType(), 0, SC_Extern, SC_None); - DeclRefExpr *DRE = new (Context) DeclRefExpr(VD, getProtocolType(), VK_LValue, - SourceLocation()); + DeclRefExpr *DRE = new (Context) DeclRefExpr(VD, false, getProtocolType(), + VK_LValue, SourceLocation()); Expr *DerefExpr = new (Context) UnaryOperator(DRE, UO_AddrOf, Context->getPointerType(DRE->getType()), VK_RValue, OK_Ordinary, SourceLocation()); @@ -3630,20 +3633,20 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart, // Need to copy-in the inner copied-in variables not actually used in this // block. for (int j = 0; j < InnerDeclRefsCount[i]; j++) { - BlockDeclRefExpr *Exp = InnerDeclRefs[count++]; + DeclRefExpr *Exp = InnerDeclRefs[count++]; ValueDecl *VD = Exp->getDecl(); BlockDeclRefs.push_back(Exp); - if (!Exp->isByRef() && !BlockByCopyDeclsPtrSet.count(VD)) { + if (!VD->hasAttr() && !BlockByCopyDeclsPtrSet.count(VD)) { BlockByCopyDeclsPtrSet.insert(VD); BlockByCopyDecls.push_back(VD); } - if (Exp->isByRef() && !BlockByRefDeclsPtrSet.count(VD)) { + if (VD->hasAttr() && !BlockByRefDeclsPtrSet.count(VD)) { BlockByRefDeclsPtrSet.insert(VD); BlockByRefDecls.push_back(VD); } // imported objects in the inner blocks not used in the outer // blocks must be copied/disposed in the outer block as well. - if (Exp->isByRef() || + if (VD->hasAttr() || VD->getType()->isObjCObjectPointerType() || VD->getType()->isBlockPointerType()) ImportedBlockDecls.insert(VD); @@ -3732,25 +3735,21 @@ void RewriteObjC::GetBlockDeclRefExprs(Stmt *S) { GetBlockDeclRefExprs(*CI); } // Handle specific things. - if (BlockDeclRefExpr *CDRE = dyn_cast(S)) { - // FIXME: Handle enums. - if (!isa(CDRE->getDecl())) - BlockDeclRefs.push_back(CDRE); - } - else if (DeclRefExpr *DRE = dyn_cast(S)) - if (HasLocalVariableExternalStorage(DRE->getDecl())) { - BlockDeclRefExpr *BDRE = - new (Context)BlockDeclRefExpr(cast(DRE->getDecl()), - DRE->getType(), - VK_LValue, DRE->getLocation(), false); - BlockDeclRefs.push_back(BDRE); + if (DeclRefExpr *DRE = dyn_cast(S)) { + if (DRE->refersToEnclosingLocal()) { + // FIXME: Handle enums. + if (!isa(DRE->getDecl())) + BlockDeclRefs.push_back(DRE); + if (HasLocalVariableExternalStorage(DRE->getDecl())) + BlockDeclRefs.push_back(DRE); } + } return; } void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S, - SmallVector &InnerBlockDeclRefs, + SmallVector &InnerBlockDeclRefs, llvm::SmallPtrSet &InnerContexts) { for (Stmt::child_range CI = S->children(); CI; ++CI) if (*CI) { @@ -3767,15 +3766,15 @@ void RewriteObjC::GetInnerBlockDeclRefExprs(Stmt *S, } // Handle specific things. - if (BlockDeclRefExpr *CDRE = dyn_cast(S)) { - if (!isa(CDRE->getDecl()) && - !InnerContexts.count(CDRE->getDecl()->getDeclContext())) - InnerBlockDeclRefs.push_back(CDRE); - } - else if (DeclRefExpr *DRE = dyn_cast(S)) { - if (VarDecl *Var = dyn_cast(DRE->getDecl())) - if (Var->isFunctionOrMethodVarDecl()) - ImportedLocalExternalDecls.insert(Var); + if (DeclRefExpr *DRE = dyn_cast(S)) { + if (DRE->refersToEnclosingLocal()) { + if (!isa(DRE->getDecl()) && + !InnerContexts.count(DRE->getDecl()->getDeclContext())) + InnerBlockDeclRefs.push_back(DRE); + if (VarDecl *Var = dyn_cast(DRE->getDecl())) + if (Var->isFunctionOrMethodVarDecl()) + ImportedLocalExternalDecls.insert(Var); + } } return; @@ -3818,9 +3817,6 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { if (const DeclRefExpr *DRE = dyn_cast(BlockExp)) { CPT = DRE->getType()->getAs(); - } else if (const BlockDeclRefExpr *CDRE = - dyn_cast(BlockExp)) { - CPT = CDRE->getType()->getAs(); } else if (const MemberExpr *MExpr = dyn_cast(BlockExp)) { CPT = MExpr->getType()->getAs(); } @@ -3933,17 +3929,11 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { // i = 77; // }; //} -Stmt *RewriteObjC::RewriteBlockDeclRefExpr(Expr *DeclRefExp) { +Stmt *RewriteObjC::RewriteBlockDeclRefExpr(DeclRefExpr *DeclRefExp) { // Rewrite the byref variable into BYREFVAR->__forwarding->BYREFVAR // for each DeclRefExp where BYREFVAR is name of the variable. - ValueDecl *VD; - bool isArrow = true; - if (BlockDeclRefExpr *BDRE = dyn_cast(DeclRefExp)) - VD = BDRE->getDecl(); - else { - VD = cast(DeclRefExp)->getDecl(); - isArrow = false; - } + ValueDecl *VD = DeclRefExp->getDecl(); + bool isArrow = DeclRefExp->refersToEnclosingLocal(); FieldDecl *FD = FieldDecl::Create(*Context, 0, SourceLocation(), SourceLocation(), @@ -4437,7 +4427,7 @@ void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { if (BlockDeclRefs.size()) { // Unique all "by copy" declarations. for (unsigned i = 0; i < BlockDeclRefs.size(); i++) - if (!BlockDeclRefs[i]->isByRef()) { + if (!BlockDeclRefs[i]->getDecl()->hasAttr()) { if (!BlockByCopyDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) { BlockByCopyDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl()); BlockByCopyDecls.push_back(BlockDeclRefs[i]->getDecl()); @@ -4445,7 +4435,7 @@ void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { } // Unique all "by ref" declarations. for (unsigned i = 0; i < BlockDeclRefs.size(); i++) - if (BlockDeclRefs[i]->isByRef()) { + if (BlockDeclRefs[i]->getDecl()->hasAttr()) { if (!BlockByRefDeclsPtrSet.count(BlockDeclRefs[i]->getDecl())) { BlockByRefDeclsPtrSet.insert(BlockDeclRefs[i]->getDecl()); BlockByRefDecls.push_back(BlockDeclRefs[i]->getDecl()); @@ -4453,7 +4443,7 @@ void RewriteObjC::CollectBlockDeclRefInfo(BlockExpr *Exp) { } // Find any imported blocks...they will need special attention. for (unsigned i = 0; i < BlockDeclRefs.size(); i++) - if (BlockDeclRefs[i]->isByRef() || + if (BlockDeclRefs[i]->getDecl()->hasAttr() || BlockDeclRefs[i]->getType()->isObjCObjectPointerType() || BlockDeclRefs[i]->getType()->isBlockPointerType()) ImportedBlockDecls.insert(BlockDeclRefs[i]->getDecl()); @@ -4469,7 +4459,7 @@ FunctionDecl *RewriteObjC::SynthBlockInitFunctionDecl(StringRef name) { } Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, - const SmallVector &InnerBlockDeclRefs) { + const SmallVector &InnerBlockDeclRefs) { const BlockDecl *block = Exp->getBlockDecl(); Blocks.push_back(Exp); @@ -4479,9 +4469,9 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, int countOfInnerDecls = 0; if (!InnerBlockDeclRefs.empty()) { for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) { - BlockDeclRefExpr *Exp = InnerBlockDeclRefs[i]; + DeclRefExpr *Exp = InnerBlockDeclRefs[i]; ValueDecl *VD = Exp->getDecl(); - if (!Exp->isByRef() && !BlockByCopyDeclsPtrSet.count(VD)) { + if (!VD->hasAttr() && !BlockByCopyDeclsPtrSet.count(VD)) { // We need to save the copied-in variables in nested // blocks because it is needed at the end for some of the API generations. // See SynthesizeBlockLiterals routine. @@ -4490,7 +4480,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, BlockByCopyDeclsPtrSet.insert(VD); BlockByCopyDecls.push_back(VD); } - if (Exp->isByRef() && !BlockByRefDeclsPtrSet.count(VD)) { + if (VD->hasAttr() && !BlockByRefDeclsPtrSet.count(VD)) { InnerDeclRefs.push_back(Exp); countOfInnerDecls++; BlockDeclRefs.push_back(Exp); BlockByRefDeclsPtrSet.insert(VD); @@ -4499,7 +4489,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, } // Find any imported blocks...they will need special attention. for (unsigned i = 0; i < InnerBlockDeclRefs.size(); i++) - if (InnerBlockDeclRefs[i]->isByRef() || + if (InnerBlockDeclRefs[i]->getDecl()->hasAttr() || InnerBlockDeclRefs[i]->getType()->isObjCObjectPointerType() || InnerBlockDeclRefs[i]->getType()->isBlockPointerType()) ImportedBlockDecls.insert(InnerBlockDeclRefs[i]->getDecl()); @@ -4529,15 +4519,15 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, // Simulate a contructor call... FD = SynthBlockInitFunctionDecl(Tag); - DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, FType, VK_RValue, + DeclRefExpr *DRE = new (Context) DeclRefExpr(FD, false, FType, VK_RValue, SourceLocation()); SmallVector InitExprs; // Initialize the block function. FD = SynthBlockInitFunctionDecl(Func); - DeclRefExpr *Arg = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, - SourceLocation()); + DeclRefExpr *Arg = new (Context) DeclRefExpr(FD, false, FD->getType(), + VK_LValue, SourceLocation()); CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, CK_BitCast, Arg); InitExprs.push_back(castExpr); @@ -4551,7 +4541,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, Context->VoidPtrTy, 0, SC_Static, SC_None); UnaryOperator *DescRefExpr = - new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, + new (Context) UnaryOperator(new (Context) DeclRefExpr(NewVD, false, Context->VoidPtrTy, VK_LValue, SourceLocation()), @@ -4570,7 +4560,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, if (isObjCType((*I)->getType())) { // FIXME: Conform to ABI ([[obj retain] autorelease]). FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, + Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, SourceLocation()); if (HasLocalVariableExternalStorage(*I)) { QualType QT = (*I)->getType(); @@ -4580,13 +4570,13 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, } } else if (isTopLevelBlockPointerType((*I)->getType())) { FD = SynthBlockInitFunctionDecl((*I)->getName()); - Arg = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, + Arg = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, SourceLocation()); Exp = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, CK_BitCast, Arg); } else { FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, + Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, SourceLocation()); if (HasLocalVariableExternalStorage(*I)) { QualType QT = (*I)->getType(); @@ -4614,7 +4604,7 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); FD = SynthBlockInitFunctionDecl((*I)->getName()); - Exp = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue, + Exp = new (Context) DeclRefExpr(FD, false, FD->getType(), VK_LValue, SourceLocation()); bool isNestedCapturedVar = false; if (block) @@ -4708,7 +4698,7 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { } if (BlockExpr *BE = dyn_cast(S)) { - SmallVector InnerBlockDeclRefs; + SmallVector InnerBlockDeclRefs; llvm::SmallPtrSet InnerContexts; InnerContexts.insert(BE->getBlockDecl()); ImportedLocalExternalDecls.clear(); @@ -4853,10 +4843,6 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) { Stmts.pop_back(); } // Handle blocks rewriting. - if (BlockDeclRefExpr *BDRE = dyn_cast(S)) { - if (BDRE->isByRef()) - return RewriteBlockDeclRefExpr(BDRE); - } if (DeclRefExpr *DRE = dyn_cast(S)) { ValueDecl *VD = DRE->getDecl(); if (VD->hasAttr()) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index ad763c346d41..f546bbe1fdb6 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -983,6 +983,7 @@ Sema::SemaBuiltinAtomicOverloaded(ExprResult TheCallResult) { DRE->getQualifierLoc(), SourceLocation(), NewBuiltinDecl, + /*enclosing*/ false, DRE->getLocation(), NewBuiltinDecl->getType(), DRE->getValueKind()); @@ -4674,12 +4675,6 @@ static bool findRetainCycleOwner(Sema &S, Expr *e, RetainCycleOwner &owner) { return considerVariable(var, ref, owner); } - if (BlockDeclRefExpr *ref = dyn_cast(e)) { - owner.Variable = ref->getDecl(); - owner.setLocsFrom(ref); - return true; - } - if (MemberExpr *member = dyn_cast(e)) { if (member->isArrow()) return false; @@ -4736,11 +4731,6 @@ namespace { Capturer = ref; } - void VisitBlockDeclRefExpr(BlockDeclRefExpr *ref) { - if (ref->getDecl() == Variable && !Capturer) - Capturer = ref; - } - void VisitObjCIvarRefExpr(ObjCIvarRefExpr *ref) { if (Capturer) return; Visit(ref->getBase()); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e3527a8289cc..f6e3aa721586 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -6721,7 +6721,7 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { if (type->isStructureOrClassType()) { SourceLocation poi = var->getLocation(); - Expr *varRef = new (Context) DeclRefExpr(var, type, VK_LValue, poi); + Expr *varRef =new (Context) DeclRefExpr(var, false, type, VK_LValue, poi); ExprResult result = PerformCopyInitialization( InitializedEntity::InitializeBlock(poi, type, false), diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index e84f66b96367..a5b74575b6b2 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2415,7 +2415,7 @@ BuildImplicitBaseInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, Expr *CopyCtorArg = DeclRefExpr::Create(SemaRef.Context, NestedNameSpecifierLoc(), - SourceLocation(), Param, + SourceLocation(), Param, false, Constructor->getLocation(), ParamType, VK_LValue, 0); @@ -2491,7 +2491,7 @@ BuildImplicitMemberInitializer(Sema &SemaRef, CXXConstructorDecl *Constructor, Expr *MemberExprBase = DeclRefExpr::Create(SemaRef.Context, NestedNameSpecifierLoc(), - SourceLocation(), Param, + SourceLocation(), Param, false, Loc, ParamType, VK_LValue, 0); SemaRef.MarkDeclRefReferenced(cast(MemberExprBase)); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 85778e4a439a..a57e2ac9b23f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1266,11 +1266,16 @@ Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, } } + bool refersToEnclosingScope = + (CurContext != D->getDeclContext() && + D->getDeclContext()->isFunctionOrMethod()); + DeclRefExpr *E = DeclRefExpr::Create(Context, SS ? SS->getWithLocInContext(Context) : NestedNameSpecifierLoc(), - SourceLocation(), - D, NameInfo, Ty, VK); + SourceLocation(), + D, refersToEnclosingScope, + NameInfo, Ty, VK); MarkDeclRefReferenced(E); @@ -2146,42 +2151,6 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS, return Owned(ULE); } -static bool shouldBuildBlockDeclRef(ValueDecl *D, Sema &S) { - // Check for a variable with local storage not from the current scope; - // we need to create BlockDeclRefExprs for these. - // FIXME: BlockDeclRefExpr shouldn't exist! - VarDecl *var = dyn_cast(D); - if (!var) - return false; - if (var->getDeclContext() == S.CurContext) - return false; - if (!var->hasLocalStorage()) - return false; - return S.getCurBlock() != 0; -} - -static ExprResult BuildBlockDeclRefExpr(Sema &S, ValueDecl *VD, - const DeclarationNameInfo &NameInfo) { - VarDecl *var = cast(VD); - QualType exprType = var->getType().getNonReferenceType(); - - bool HasBlockAttr = var->hasAttr(); - bool ConstAdded = false; - if (!HasBlockAttr) { - ConstAdded = !exprType.isConstQualified(); - exprType.addConst(); - } - - BlockDeclRefExpr *BDRE = - new (S.Context) BlockDeclRefExpr(var, exprType, VK_LValue, - NameInfo.getLoc(), HasBlockAttr, - ConstAdded); - - S.MarkBlockDeclRefReferenced(BDRE); - - return S.Owned(BDRE); -} - /// \brief Complete semantic analysis for a reference to the given declaration. ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS, @@ -2304,9 +2273,6 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS, valueKind = VK_LValue; type = type.getNonReferenceType(); - if (shouldBuildBlockDeclRef(VD, *this)) - return BuildBlockDeclRefExpr(*this, VD, NameInfo); - // FIXME: Does the addition of const really only apply in // potentially-evaluated contexts? Since the variable isn't actually // captured in an unevaluated context, it seems that the answer is no. @@ -3721,7 +3687,7 @@ Sema::ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, QualType ConfigQTy = ConfigDecl->getType(); DeclRefExpr *ConfigDR = new (Context) DeclRefExpr( - ConfigDecl, ConfigQTy, VK_LValue, LLLLoc); + ConfigDecl, false, ConfigQTy, VK_LValue, LLLLoc); MarkFunctionReferenced(LLLLoc, ConfigDecl); return ActOnCallExpr(S, ConfigDR, LLLLoc, ExecConfig, GGGLoc, 0, @@ -9863,7 +9829,8 @@ static ExprResult captureInLambda(Sema &S, LambdaScopeInfo *LSI, // C++ [expr.prim.labda]p12: // An entity captured by a lambda-expression is odr-used (3.2) in // the scope containing the lambda-expression. - Expr *Ref = new (S.Context) DeclRefExpr(Var, DeclRefType, VK_LValue, Loc); + Expr *Ref = new (S.Context) DeclRefExpr(Var, false, DeclRefType, + VK_LValue, Loc); Var->setReferenced(true); Var->setUsed(true); @@ -10109,7 +10076,7 @@ bool Sema::tryCaptureVariable(VarDecl *Var, SourceLocation Loc, // According to the blocks spec, the capture of a variable from // the stack requires a const copy constructor. This is not true // of the copy/move done to move a __block variable to the heap. - Expr *DeclRef = new (Context) DeclRefExpr(Var, + Expr *DeclRef = new (Context) DeclRefExpr(Var, false, DeclRefType.withConst(), VK_LValue, Loc); ExprResult Result @@ -10278,10 +10245,7 @@ void Sema::CleanupVarDeclMarking() { i != e; ++i) { VarDecl *Var; SourceLocation Loc; - if (BlockDeclRefExpr *BDRE = dyn_cast(*i)) { - Var = BDRE->getDecl(); - Loc = BDRE->getLocation(); - } else if (DeclRefExpr *DRE = dyn_cast(*i)) { + if (DeclRefExpr *DRE = dyn_cast(*i)) { Var = cast(DRE->getDecl()); Loc = DRE->getLocation(); } else if (MemberExpr *ME = dyn_cast(*i)) { @@ -10365,12 +10329,6 @@ static void MarkExprReferenced(Sema &SemaRef, SourceLocation Loc, SemaRef.MarkAnyDeclReferenced(Loc, D); } -/// \brief Perform reference-marking and odr-use handling for a -/// BlockDeclRefExpr. -void Sema::MarkBlockDeclRefReferenced(BlockDeclRefExpr *E) { - MarkExprReferenced(*this, E->getLocation(), E->getDecl(), E); -} - /// \brief Perform reference-marking and odr-use handling for a DeclRefExpr. void Sema::MarkDeclRefReferenced(DeclRefExpr *E) { MarkExprReferenced(*this, E->getLocation(), E->getDecl(), E); @@ -10497,14 +10455,6 @@ namespace { Inherited::VisitCXXConstructExpr(E); } - void VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { - // If we were asked not to visit local variables, don't. - if (SkipLocalVariables && E->getDecl()->hasLocalStorage()) - return; - - S.MarkBlockDeclRefReferenced(E); - } - void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { Visit(E->getExpr()); } diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 0f1db2b12d67..8eeb09ebbd3a 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2187,6 +2187,7 @@ ExprResult Sema::CheckConditionVariable(VarDecl *ConditionVar, Owned(DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), SourceLocation(), ConditionVar, + /*enclosing*/ false, ConditionVar->getLocation(), ConditionVar->getType().getNonReferenceType(), VK_LValue)); diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 7c1de21385e0..5de785207fd6 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -3872,16 +3872,11 @@ static InvalidICRKind isInvalidICRSource(ASTContext &C, Expr *e, } // If we have a declaration reference, it had better be a local variable. - } else if (isa(e) || isa(e)) { + } else if (isa(e)) { if (!isAddressOf) return IIK_nonlocal; - VarDecl *var; - if (isa(e)) { - var = dyn_cast(cast(e)->getDecl()); - if (!var) return IIK_nonlocal; - } else { - var = cast(e)->getDecl(); - } + VarDecl *var = dyn_cast(cast(e)->getDecl()); + if (!var) return IIK_nonlocal; return (var->hasLocalStorage() ? IIK_okay : IIK_nonlocal); diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp index 77458e0cbe22..617460d492b8 100644 --- a/clang/lib/Sema/SemaObjCProperty.cpp +++ b/clang/lib/Sema/SemaObjCProperty.cpp @@ -834,7 +834,7 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S, // FIXME. Eventually we want to do this for Objective-C as well. ImplicitParamDecl *SelfDecl = getterMethod->getSelfDecl(); DeclRefExpr *SelfExpr = - new (Context) DeclRefExpr(SelfDecl, SelfDecl->getType(), + new (Context) DeclRefExpr(SelfDecl, false, SelfDecl->getType(), VK_RValue, SourceLocation()); Expr *IvarRefExpr = new (Context) ObjCIvarRefExpr(Ivar, Ivar->getType(), AtLoc, @@ -867,7 +867,7 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S, // FIXME. Eventually we want to do this for Objective-C as well. ImplicitParamDecl *SelfDecl = setterMethod->getSelfDecl(); DeclRefExpr *SelfExpr = - new (Context) DeclRefExpr(SelfDecl, SelfDecl->getType(), + new (Context) DeclRefExpr(SelfDecl, false, SelfDecl->getType(), VK_RValue, SourceLocation()); Expr *lhs = new (Context) ObjCIvarRefExpr(Ivar, Ivar->getType(), AtLoc, @@ -875,7 +875,7 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S, ObjCMethodDecl::param_iterator P = setterMethod->param_begin(); ParmVarDecl *Param = (*P); QualType T = Param->getType().getNonReferenceType(); - Expr *rhs = new (Context) DeclRefExpr(Param, T, + Expr *rhs = new (Context) DeclRefExpr(Param, false, T, VK_LValue, SourceLocation()); ExprResult Res = BuildBinOp(S, lhs->getLocEnd(), BO_Assign, lhs, rhs); diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 22b145c59a1c..49301c2dc2ca 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -40,7 +40,7 @@ static ExprResult CreateFunctionRefExpr(Sema &S, FunctionDecl *Fn, bool HadMultipleCandidates, SourceLocation Loc = SourceLocation(), const DeclarationNameLoc &LocInfo = DeclarationNameLoc()){ - DeclRefExpr *DRE = new (S.Context) DeclRefExpr(Fn, Fn->getType(), + DeclRefExpr *DRE = new (S.Context) DeclRefExpr(Fn, false, Fn->getType(), VK_LValue, Loc, LocInfo); if (HadMultipleCandidates) DRE->setHadMultipleCandidates(true); @@ -5580,7 +5580,7 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion, // lvalues/rvalues and the type. Fortunately, we can allocate this // call on the stack and we don't need its arguments to be // well-formed. - DeclRefExpr ConversionRef(Conversion, Conversion->getType(), + DeclRefExpr ConversionRef(Conversion, false, Conversion->getType(), VK_LValue, From->getLocStart()); ImplicitCastExpr ConversionFn(ImplicitCastExpr::OnStack, Context.getPointerType(Conversion->getType()), @@ -11053,6 +11053,7 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, DeclAccessPair Found, ULE->getQualifierLoc(), ULE->getTemplateKeywordLoc(), Fn, + /*enclosing*/ false, // FIXME? ULE->getNameLoc(), Fn->getType(), VK_LValue, @@ -11080,6 +11081,7 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, DeclAccessPair Found, MemExpr->getQualifierLoc(), MemExpr->getTemplateKeywordLoc(), Fn, + /*enclosing*/ false, MemExpr->getMemberLoc(), Fn->getType(), VK_LValue, diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp index d661d866c44e..9528f4c37473 100644 --- a/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp @@ -73,15 +73,6 @@ namespace { return true; } - // \brief Record occurrences of function and non-type template parameter - // packs in a block-captured expression. - bool VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { - if (E->getDecl()->isParameterPack()) - Unexpanded.push_back(std::make_pair(E->getDecl(), E->getLocation())); - - return true; - } - /// \brief Record occurrences of template template parameter packs. bool TraverseTemplateName(TemplateName Template) { if (TemplateTemplateParmDecl *TTP diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 8d4d934402b4..9bb51b4124fb 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -2399,7 +2399,8 @@ public: // Build a reference to the __builtin_shufflevector builtin FunctionDecl *Builtin = cast(*Lookup.first); ExprResult Callee - = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), + = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false, + Builtin->getType(), VK_LValue, BuiltinLoc)); Callee = SemaRef.UsualUnaryConversions(Callee.take()); if (Callee.isInvalid()) @@ -8768,29 +8769,6 @@ TreeTransform::TransformBlockExpr(BlockExpr *E) { /*Scope=*/0); } -template -ExprResult -TreeTransform::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { - ValueDecl *ND - = cast_or_null(getDerived().TransformDecl(E->getLocation(), - E->getDecl())); - if (!ND) - return ExprError(); - - if (!getDerived().AlwaysRebuild() && - ND == E->getDecl()) { - // Mark it referenced in the new context regardless. - // FIXME: this is a bit instantiation-specific. - SemaRef.MarkBlockDeclRefReferenced(E); - - return SemaRef.Owned(E); - } - - DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); - return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), - ND, NameInfo, 0); -} - template ExprResult TreeTransform::TransformAsTypeExpr(AsTypeExpr *E) { diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index a0d7e457e0c5..d8289f227f50 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -333,6 +333,7 @@ void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) { E->DeclRefExprBits.HasFoundDecl = Record[Idx++]; E->DeclRefExprBits.HasTemplateKWAndArgsInfo = Record[Idx++]; E->DeclRefExprBits.HadMultipleCandidates = Record[Idx++]; + E->DeclRefExprBits.RefersToEnclosingLocal = Record[Idx++]; unsigned NumTemplateArgs = 0; if (E->hasTemplateKWAndArgsInfo()) NumTemplateArgs = Record[Idx++]; @@ -752,14 +753,6 @@ void ASTStmtReader::VisitBlockExpr(BlockExpr *E) { E->setBlockDecl(ReadDeclAs(Record, Idx)); } -void ASTStmtReader::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { - VisitExpr(E); - E->setDecl(ReadDeclAs(Record, Idx)); - E->setLocation(ReadSourceLocation(Record, Idx)); - E->setByRef(Record[Idx++]); - E->setConstQualAdded(Record[Idx++]); -} - void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) { VisitExpr(E); E->NumAssocs = Record[Idx++]; @@ -1703,7 +1696,7 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1], /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 2], /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ? - Record[ASTStmtReader::NumExprFields + 4] : 0); + Record[ASTStmtReader::NumExprFields + 5] : 0); break; case EXPR_INTEGER_LITERAL: @@ -1882,10 +1875,6 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { S = new (Context) BlockExpr(Empty); break; - case EXPR_BLOCK_DECL_REF: - S = new (Context) BlockDeclRefExpr(Empty); - break; - case EXPR_GENERIC_SELECTION: S = new (Context) GenericSelectionExpr(Empty); break; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index d21dac68de15..f457393dcf0e 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -693,7 +693,6 @@ static void AddStmtsExprs(llvm::BitstreamWriter &Stream, RECORD(EXPR_GNU_NULL); RECORD(EXPR_SHUFFLE_VECTOR); RECORD(EXPR_BLOCK); - RECORD(EXPR_BLOCK_DECL_REF); RECORD(EXPR_GENERIC_SELECTION); RECORD(EXPR_OBJC_STRING_LITERAL); RECORD(EXPR_OBJC_NUMERIC_LITERAL); diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index d838e738dfd5..a8e3c77cffd9 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -1553,6 +1553,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() { Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //RefersToEnclosingLocal Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location DeclRefExprAbbrev = Stream.EmitAbbrev(Abv); diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index a59f2b6a7781..791403b5a220 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -266,6 +266,7 @@ void ASTStmtWriter::VisitDeclRefExpr(DeclRefExpr *E) { Record.push_back(E->getDecl() != E->getFoundDecl()); Record.push_back(E->hasTemplateKWAndArgsInfo()); Record.push_back(E->hadMultipleCandidates()); + Record.push_back(E->refersToEnclosingLocal()); if (E->hasTemplateKWAndArgsInfo()) { unsigned NumTemplateArgs = E->getNumTemplateArgs(); @@ -712,15 +713,6 @@ void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) { Code = serialization::EXPR_BLOCK; } -void ASTStmtWriter::VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { - VisitExpr(E); - Writer.AddDeclRef(E->getDecl(), Record); - Writer.AddSourceLocation(E->getLocation(), Record); - Record.push_back(E->isByRef()); - Record.push_back(E->isConstQualAdded()); - Code = serialization::EXPR_BLOCK_DECL_REF; -} - void ASTStmtWriter::VisitGenericSelectionExpr(GenericSelectionExpr *E) { VisitExpr(E); Record.push_back(E->getNumAssocs()); diff --git a/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp index df47b04e379c..c08f163a1f7b 100644 --- a/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/IdempotentOperationChecker.cpp @@ -650,7 +650,6 @@ bool IdempotentOperationChecker::CanVary(const Expr *Ex, case Stmt::InitListExprClass: case Stmt::DesignatedInitExprClass: case Stmt::BlockExprClass: - case Stmt::BlockDeclRefExprClass: return false; // Cases requiring custom logic diff --git a/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp index 8a46035feec8..d57767eec9fb 100644 --- a/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp @@ -33,16 +33,16 @@ public: }; } // end anonymous namespace -static const BlockDeclRefExpr *FindBlockDeclRefExpr(const Stmt *S, - const VarDecl *VD){ - if (const BlockDeclRefExpr *BR = dyn_cast(S)) +static const DeclRefExpr *FindBlockDeclRefExpr(const Stmt *S, + const VarDecl *VD) { + if (const DeclRefExpr *BR = dyn_cast(S)) if (BR->getDecl() == VD) return BR; for (Stmt::const_child_iterator I = S->child_begin(), E = S->child_end(); I!=E; ++I) if (const Stmt *child = *I) { - const BlockDeclRefExpr *BR = FindBlockDeclRefExpr(child, VD); + const DeclRefExpr *BR = FindBlockDeclRefExpr(child, VD); if (BR) return BR; } diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index d9f983944413..3d1d6ea8a9fe 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -670,14 +670,6 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, Bldr.addNodes(Dst); break; - case Stmt::BlockDeclRefExprClass: { - Bldr.takeNodes(Pred); - const BlockDeclRefExpr *BE = cast(S); - VisitCommonDeclRefExpr(BE, BE->getDecl(), Pred, Dst); - Bldr.addNodes(Dst); - break; - } - case Stmt::BlockExprClass: Bldr.takeNodes(Pred); VisitBlockExpr(cast(S), Pred, Dst); diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index a91146c8b3fb..92c9fde041cf 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2819,8 +2819,6 @@ static Decl *getDeclFromExpr(Stmt *E) { if (DeclRefExpr *RefExpr = dyn_cast(E)) return RefExpr->getDecl(); - if (BlockDeclRefExpr *RefExpr = dyn_cast(E)) - return RefExpr->getDecl(); if (MemberExpr *ME = dyn_cast(E)) return ME->getMemberDecl(); if (ObjCIvarRefExpr *RE = dyn_cast(E)) @@ -2862,8 +2860,6 @@ static SourceLocation getLocationFromExpr(Expr *E) { return /*FIXME:*/Msg->getLeftLoc(); if (DeclRefExpr *DRE = dyn_cast(E)) return DRE->getLocation(); - if (BlockDeclRefExpr *RefExpr = dyn_cast(E)) - return RefExpr->getLocation(); if (MemberExpr *Member = dyn_cast(E)) return Member->getMemberLoc(); if (ObjCIvarRefExpr *Ivar = dyn_cast(E)) diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index a141af3c2b99..84a6ccb07e2b 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -420,7 +420,6 @@ CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, CXTranslationUnit TU, K = CXCursor_SizeOfPackExpr; break; - case Stmt::BlockDeclRefExprClass: case Stmt::DeclRefExprClass: case Stmt::DependentScopeDeclRefExprClass: case Stmt::SubstNonTypeTemplateParmExprClass: