summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/DeclBase.cpp23
-rw-r--r--clang/lib/Sema/SemaDecl.cpp12
2 files changed, 19 insertions, 16 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index ca67e28c717..3e968c78962 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -121,15 +121,7 @@ Decl::~Decl() {
if (isOutOfSemaDC())
delete getMultipleDC();
- if (!HasAttrs)
- return;
-
- DeclAttrMapTy::iterator it = DeclAttrs->find(this);
- assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!");
-
- // release attributes.
- delete it->second;
- invalidateAttrs();
+ assert(!HasAttrs && "attributes should have been freed by Destroy");
}
void Decl::addAttr(Attr *NewAttr) {
@@ -189,7 +181,18 @@ void Decl::swapAttrs(Decl *RHS) {
}
-void Decl::Destroy(ASTContext& C) {
+void Decl::Destroy(ASTContext &C) {
+ // Free attributes for this decl.
+ if (HasAttrs) {
+ DeclAttrMapTy::iterator it = DeclAttrs->find(this);
+ assert(it != DeclAttrs->end() && "No attrs found but HasAttrs is true!");
+
+ // release attributes.
+ it->second->Destroy(C);
+ invalidateAttrs();
+ HasAttrs = false;
+ }
+
#if 0
// FIXME: Once ownership is fully understood, we can enable this code
if (DeclContext *DC = dyn_cast<DeclContext>(this))
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8d32578c98c..6a6628f748e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -482,11 +482,11 @@ static bool DeclHasAttr(const Decl *decl, const Attr *target) {
}
/// MergeAttributes - append attributes from the Old decl to the New one.
-static void MergeAttributes(Decl *New, Decl *Old) {
- Attr *attr = const_cast<Attr*>(Old->getAttrs()), *tmp;
+static void MergeAttributes(Decl *New, Decl *Old, ASTContext &C) {
+ Attr *attr = const_cast<Attr*>(Old->getAttrs());
while (attr) {
- tmp = attr;
+ Attr *tmp = attr;
attr = attr->getNext();
if (!DeclHasAttr(New, tmp) && tmp->isMerged()) {
@@ -494,7 +494,7 @@ static void MergeAttributes(Decl *New, Decl *Old) {
New->addAttr(tmp);
} else {
tmp->setNext(0);
- delete(tmp);
+ tmp->Destroy(C);
}
}
@@ -678,7 +678,7 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) {
/// \returns false
bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old) {
// Merge the attributes
- MergeAttributes(New, Old);
+ MergeAttributes(New, Old, Context);
// Merge the storage class.
New->setStorageClass(Old->getStorageClass());
@@ -767,7 +767,7 @@ bool Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
return true;
}
- MergeAttributes(New, Old);
+ MergeAttributes(New, Old, Context);
// Merge the types
QualType MergedT = Context.mergeTypes(New->getType(), Old->getType());
OpenPOWER on IntegriCloud