From: Fariborz Jahanian Date: Thu, 23 Jun 2011 17:50:10 +0000 (+0000) Subject: Remove multiple use of weak_import attribute on X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3ca14d13741889a9b924d0ca32e818f07a9834a;p=clang Remove multiple use of weak_import attribute on same declaration. Templatize dropAttr for general use. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133724 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 8d1ef8f06e..d39ad72bd7 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -363,7 +363,6 @@ public: const AttrVec &getAttrs() const; void swapAttrs(Decl *D); void dropAttrs(); - void dropWeakImportAttr(); void addAttr(Attr *A) { if (hasAttrs()) @@ -382,7 +381,10 @@ public: attr_iterator attr_end() const { return hasAttrs() ? getAttrs().end() : 0; } - + + template + void dropAttr(); + template specific_attr_iterator specific_attr_begin() const { return specific_attr_iterator(attr_begin()); diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index c183e61df8..69724a3d5e 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -520,20 +520,6 @@ void Decl::dropAttrs() { getASTContext().eraseDeclAttrs(this); } -void Decl::dropWeakImportAttr() { - if (!HasAttrs) return; - AttrVec &Attrs = getASTContext().getDeclAttrs(this); - for (llvm::SmallVectorImpl::iterator A = Attrs.begin(); - A != Attrs.end(); ++A) { - if (isa(*A)) { - Attrs.erase(A); - break; - } - } - if (Attrs.empty()) - HasAttrs = false; -} - const AttrVec &Decl::getAttrs() const { assert(HasAttrs && "No attrs to get!"); return getASTContext().getDeclAttrs(this); @@ -585,6 +571,22 @@ Decl *Decl::castFromDeclContext (const DeclContext *D) { } } +template +void Decl::dropAttr() { + if (!HasAttrs) return; + AttrVec &Attrs = getASTContext().getDeclAttrs(this); + for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { + if (isa(Attrs[i])) { + Attrs.erase(Attrs.begin() + i); + --i, --e; + } + } + if (Attrs.empty()) + HasAttrs = false; +} +// Force instantiation for WeakImportAttr which gets used. +template void Decl::dropAttr(); + DeclContext *Decl::castToDeclContext(const Decl *D) { Decl::Kind DK = D->getKind(); switch(DK) { diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 487390bc29..4a000e9fc2 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2046,7 +2046,7 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName(); Diag(Old->getLocation(), diag::note_previous_definition); // Remove weak_import attribute on new declaration. - New->dropWeakImportAttr(); + New->dropAttr(); } // Merge the types.