From: Fariborz Jahanian Date: Mon, 12 Jul 2010 21:12:19 +0000 (+0000) Subject: Copy over attributes to instantiated variable. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cad8d31117800f804ee4f313134162edac8f8813;p=clang Copy over attributes to instantiated variable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108195 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 2d2407ffb1..cc0124394b 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -312,6 +312,7 @@ public: return getAttrsImpl(); // Uncommon case, out of line hash lookup. } void swapAttrs(Decl *D); + void copyAttrs(Decl *D); void invalidateAttrs(); template const T *getAttr() const { diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 9027a13143..ddedc65a1b 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -372,6 +372,17 @@ void Decl::swapAttrs(Decl *RHS) { RHS->HasAttrs = true; } +void Decl::copyAttrs(Decl *SRC) { + if (!SRC->hasAttrs()) + return; + ASTContext &Context = getASTContext(); + for (const Attr *attr = SRC->getAttrs(); attr; attr = attr->getNext()) { + Attr *NewAttr = attr->clone(Context); + addAttr(const_cast(NewAttr)); + } + HasAttrs = true; +} + void Decl::Destroy(ASTContext &C) { // Free attributes for this decl. diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 5778a827fc..3a0e43672d 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2591,7 +2591,10 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, ParentDC->isFunctionOrMethod()) { // D is a local of some kind. Look into the map of local // declarations to their instantiations. - return cast(CurrentInstantiationScope->getInstantiationOf(D)); + NamedDecl *ND = + cast(CurrentInstantiationScope->getInstantiationOf(D)); + ND->copyAttrs(D); + return ND; } if (CXXRecordDecl *Record = dyn_cast(D)) { diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 2e92d32736..db5e2d10f4 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -6279,11 +6279,6 @@ TreeTransform::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { if (!ND) return SemaRef.ExprError(); - // Is this instantiation of a __block variable? - ValueDecl *V = E->getDecl(); - if (V->getAttr()) - ND->addAttr(::new (SemaRef.Context) BlocksAttr(BlocksAttr::ByRef)); - if (!getDerived().AlwaysRebuild() && ND == E->getDecl()) { // Mark it referenced in the new context regardless.