diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 24 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 3 |
2 files changed, 18 insertions, 9 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 8d87d1cb4a2..8d9913b1aae 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -336,14 +336,9 @@ Decl::~Decl() { DeclAttrMapTy::iterator it = DeclAttrs->find(this); assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!"); - // FIXME: Properly release attributes. - // delete it->second; - DeclAttrs->erase(it); - - if (DeclAttrs->empty()) { - delete DeclAttrs; - DeclAttrs = 0; - } + // release attributes. + delete it->second; + invalidateAttrs(); } void Decl::addAttr(Attr *NewAttr) { @@ -358,6 +353,19 @@ void Decl::addAttr(Attr *NewAttr) { HasAttrs = true; } +void Decl::invalidateAttrs() { + if (!HasAttrs) return; + + HasAttrs = false; + (*DeclAttrs)[this] = 0; + DeclAttrs->erase(this); + + if (DeclAttrs->empty()) { + delete DeclAttrs; + DeclAttrs = 0; + } +} + const Attr *Decl::getAttrs() const { if (!HasAttrs) return 0; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index eb0abafcaaa..230ea3cb9da 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -276,7 +276,6 @@ static bool DeclHasAttr(const Decl *decl, const Attr *target) { static void MergeAttributes(Decl *New, Decl *Old) { Attr *attr = const_cast<Attr*>(Old->getAttrs()), *tmp; -// FIXME: fix this code to cleanup the Old attrs correctly while (attr) { tmp = attr; attr = attr->getNext(); @@ -288,6 +287,8 @@ static void MergeAttributes(Decl *New, Decl *Old) { delete(tmp); } } + + Old->invalidateAttrs(); } /// MergeFunctionDecl - We just parsed a function 'New' from |

