fix decl attributes cleaning
this plugs the leak of attributes and also fixes a crash in the test

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51862 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 8d87d1c..8d9913b 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -336,14 +336,9 @@
   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 @@
   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;