Move the static DeclAttrs map into ASTContext. Fixes <rdar://problem/6983177>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73702 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 7746035..9e31bae 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -256,7 +256,7 @@
   if (isa<OverloadedFunctionDecl>(PrevDecl))
     return true;
 
-  return PrevDecl->getAttr<OverloadableAttr>() != 0;
+  return PrevDecl->getAttr<OverloadableAttr>(Context) != 0;
 }
 
 /// Add this decl to the scope shadowed decl chains.
@@ -611,8 +611,9 @@
 
 /// DeclhasAttr - returns true if decl Declaration already has the target
 /// attribute.
-static bool DeclHasAttr(const Decl *decl, const Attr *target) {
-  for (const Attr *attr = decl->getAttrs(); attr; attr = attr->getNext())
+static bool 
+DeclHasAttr(ASTContext &Context, const Decl *decl, const Attr *target) {
+  for (const Attr *attr = decl->getAttrs(Context); attr; attr = attr->getNext())
     if (attr->getKind() == target->getKind())
       return true;
 
@@ -621,11 +622,11 @@
 
 /// MergeAttributes - append attributes from the Old decl to the New one.
 static void MergeAttributes(Decl *New, Decl *Old, ASTContext &C) {
-  for (const Attr *attr = Old->getAttrs(); attr; attr = attr->getNext()) {
-    if (!DeclHasAttr(New, attr) && attr->isMerged()) {
+  for (const Attr *attr = Old->getAttrs(C); attr; attr = attr->getNext()) {
+    if (!DeclHasAttr(C, New, attr) && attr->isMerged()) {
       Attr *NewAttr = attr->clone(C);
       NewAttr->setInherited(true);
-      New->addAttr(NewAttr);
+      New->addAttr(C, NewAttr);
     }
   }
 }
@@ -1828,7 +1829,8 @@
   if (Expr *E = (Expr*) D.getAsmLabel()) {
     // The parser guarantees this is a string.
     StringLiteral *SE = cast<StringLiteral>(E);  
-    NewVD->addAttr(::new (Context) AsmLabelAttr(std::string(SE->getStrData(),
+    NewVD->addAttr(Context, 
+                   ::new (Context) AsmLabelAttr(std::string(SE->getStrData(),
                                                         SE->getByteLength())));
   }
 
@@ -1907,11 +1909,11 @@
   }
 
   if (NewVD->hasLocalStorage() && T.isObjCGCWeak()
-      && !NewVD->hasAttr<BlocksAttr>())
+      && !NewVD->hasAttr<BlocksAttr>(Context))
     Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local);
 
   bool isVM = T->isVariablyModifiedType();
-  if (isVM || NewVD->hasAttr<CleanupAttr>())
+  if (isVM || NewVD->hasAttr<CleanupAttr>(Context))
     CurFunctionNeedsScopeChecking = true;
   
   if ((isVM && NewVD->hasLinkage()) ||
@@ -1966,12 +1968,12 @@
     return NewVD->setInvalidDecl();
   }
 
-  if (!NewVD->hasLocalStorage() && NewVD->hasAttr<BlocksAttr>()) {
+  if (!NewVD->hasLocalStorage() && NewVD->hasAttr<BlocksAttr>(Context)) {
     Diag(NewVD->getLocation(), diag::err_block_on_nonlocal);
     return NewVD->setInvalidDecl();
   }
     
-  if (isVM && NewVD->hasAttr<BlocksAttr>()) {
+  if (isVM && NewVD->hasAttr<BlocksAttr>(Context)) {
     Diag(NewVD->getLocation(), diag::err_block_on_vm);
     return NewVD->setInvalidDecl();
   }
@@ -2201,7 +2203,8 @@
   if (Expr *E = (Expr*) D.getAsmLabel()) {
     // The parser guarantees this is a string.
     StringLiteral *SE = cast<StringLiteral>(E);  
-    NewFD->addAttr(::new (Context) AsmLabelAttr(std::string(SE->getStrData(),
+    NewFD->addAttr(Context,
+                   ::new (Context) AsmLabelAttr(std::string(SE->getStrData(),
                                                         SE->getByteLength())));
   }
 
@@ -2322,7 +2325,7 @@
   ProcessDeclAttributes(S, NewFD, D);
   AddKnownFunctionAttributes(NewFD);
 
-  if (OverloadableAttrRequired && !NewFD->getAttr<OverloadableAttr>()) {
+  if (OverloadableAttrRequired && !NewFD->getAttr<OverloadableAttr>(Context)) {
     // If a function name is overloadable in C, then every function
     // with that name must be marked "overloadable".
     Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing)
@@ -2330,7 +2333,7 @@
     if (PrevDecl)
       Diag(PrevDecl->getLocation(), 
            diag::note_attribute_overloadable_prev_overload);
-    NewFD->addAttr(::new (Context) OverloadableAttr());
+    NewFD->addAttr(Context, ::new (Context) OverloadableAttr());
   }
 
   // If this is a locally-scoped extern C function, update the
@@ -2930,7 +2933,7 @@
 
   ProcessDeclAttributes(S, New, D);
 
-  if (New->hasAttr<BlocksAttr>()) {
+  if (New->hasAttr<BlocksAttr>(Context)) {
     Diag(New->getLocation(), diag::err_block_on_nonlocal);
   }
   return DeclPtrTy::make(New);
@@ -3056,9 +3059,10 @@
 
   // Checking attributes of current function definition
   // dllimport attribute.
-  if (FD->getAttr<DLLImportAttr>() && (!FD->getAttr<DLLExportAttr>())) {
+  if (FD->getAttr<DLLImportAttr>(Context) && 
+      (!FD->getAttr<DLLExportAttr>(Context))) {
     // dllimport attribute cannot be applied to definition.
-    if (!(FD->getAttr<DLLImportAttr>())->isInherited()) {
+    if (!(FD->getAttr<DLLImportAttr>(Context))->isInherited()) {
       Diag(FD->getLocation(),
            diag::err_attribute_can_be_applied_only_to_symbol_declaration)
         << "dllimport";
@@ -3227,8 +3231,9 @@
     unsigned FormatIdx;
     bool HasVAListArg;
     if (Context.BuiltinInfo.isPrintfLike(BuiltinID, FormatIdx, HasVAListArg)) {
-      if (!FD->getAttr<FormatAttr>())
-        FD->addAttr(::new (Context) FormatAttr("printf", FormatIdx + 1,
+      if (!FD->getAttr<FormatAttr>(Context))
+        FD->addAttr(Context,
+                    ::new (Context) FormatAttr("printf", FormatIdx + 1,
                                              HasVAListArg ? 0 : FormatIdx + 2));
     }
 
@@ -3237,8 +3242,8 @@
     // IRgen to use LLVM intrinsics for such functions.
     if (!getLangOptions().MathErrno &&
         Context.BuiltinInfo.isConstWithoutErrno(BuiltinID)) {
-      if (!FD->getAttr<ConstAttr>())
-        FD->addAttr(::new (Context) ConstAttr());
+      if (!FD->getAttr<ConstAttr>(Context))
+        FD->addAttr(Context, ::new (Context) ConstAttr());
     }
   }
 
@@ -3256,15 +3261,17 @@
     return;
 
   if (Name->isStr("NSLog") || Name->isStr("NSLogv")) {
-    if (const FormatAttr *Format = FD->getAttr<FormatAttr>()) {
+    if (const FormatAttr *Format = FD->getAttr<FormatAttr>(Context)) {
       // FIXME: We known better than our headers.
       const_cast<FormatAttr *>(Format)->setType("printf");
     } else 
-      FD->addAttr(::new (Context) FormatAttr("printf", 1,
+      FD->addAttr(Context,
+                  ::new (Context) FormatAttr("printf", 1,
                                              Name->isStr("NSLogv") ? 0 : 2));
   } else if (Name->isStr("asprintf") || Name->isStr("vasprintf")) {
-    if (!FD->getAttr<FormatAttr>())
-      FD->addAttr(::new (Context) FormatAttr("printf", 2,
+    if (!FD->getAttr<FormatAttr>(Context))
+      FD->addAttr(Context,
+                  ::new (Context) FormatAttr("printf", 2,
                                              Name->isStr("vasprintf") ? 0 : 3));
   }
 }
@@ -3620,7 +3627,7 @@
     // the #pragma tokens are effectively skipped over during the
     // parsing of the struct).
     if (unsigned Alignment = getPragmaPackAlignment())
-      New->addAttr(::new (Context) PackedAttr(Alignment * 8));
+      New->addAttr(Context, ::new (Context) PackedAttr(Alignment * 8));
   }
 
   if (getLangOptions().CPlusPlus && SS.isEmpty() && Name && !Invalid) {
@@ -4471,7 +4478,7 @@
 
   // FIXME: This implementation is an ugly hack!
   if (PrevDecl) {
-    PrevDecl->addAttr(::new (Context) WeakAttr());
+    PrevDecl->addAttr(Context, ::new (Context) WeakAttr());
     return;
   }
   Diag(PragmaLoc, diag::err_unsupported_pragma_weak);
@@ -4487,8 +4494,8 @@
 
   // FIXME: This implementation is an ugly hack!
   if (PrevDecl) {
-    PrevDecl->addAttr(::new (Context) AliasAttr(AliasName->getName()));
-    PrevDecl->addAttr(::new (Context) WeakAttr());
+    PrevDecl->addAttr(Context, ::new (Context) AliasAttr(AliasName->getName()));
+    PrevDecl->addAttr(Context, ::new (Context) WeakAttr());
     return;
   }
   Diag(PragmaLoc, diag::err_unsupported_pragma_weak);