Revert r158700 and dependent patches r158716, r158717, and r158731.

The original r158700 caused crashes in the gcc test suite,
g++.abi/vtable3a.C among others. It also caused failures in the libc++
test suite.

llvm-svn: 158749
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 9aac837..e4545c1 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -556,6 +556,9 @@
   const CXXRecordDecl *SrcRD = 
     cast<CXXRecordDecl>(SrcType->castAs<RecordType>()->getDecl());
 
+  if (!SrcRD->hasAttr<FinalAttr>())
+    return false;
+
   const CXXRecordDecl *DestRD = 
     cast<CXXRecordDecl>(DestType->castAs<RecordType>()->getDecl());
 
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 3c14b7c..9cb9ed6 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -791,7 +791,6 @@
   if (Name.startswith("__") && Name.endswith("__") && Name.size() >= 4)
     Name = Name.substr(2, Name.size() - 4);
 
-  // FIXME: Do we need to handle namespaces here?
   return llvm::StringSwitch<bool>(Name)
 #include "clang/Lex/AttrSpellings.inc"
         .Default(false);
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 3c1c7e2..2e95a31 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -277,173 +277,67 @@
       Attrs.addNew(AttrName, SourceRange(AttrNameLoc, RParen), 0, AttrNameLoc,
                    ParmName, ParmLoc, ArgExprs.take(), ArgExprs.size(),
                    AttributeList::AS_GNU);
-    if (BuiltinType && attr->getKind() == AttributeList::AT_IBOutletCollection)
+    if (BuiltinType && attr->getKind() == AttributeList::AT_iboutletcollection)
       Diag(Tok, diag::err_iboutletcollection_builtintype);
   }
 }
 
-/// \brief Parses a single argument for a declspec, including the 
-/// surrounding parens.
-void Parser::ParseMicrosoftDeclSpecWithSingleArg(IdentifierInfo *AttrName, 
-                                                 SourceLocation AttrNameLoc,
-                                                 ParsedAttributes &Attrs)
-{
-  BalancedDelimiterTracker T(*this, tok::l_paren);
-  if (T.expectAndConsume(diag::err_expected_lparen_after, 
-                         AttrName->getNameStart(), tok::r_paren))
-    return;
 
-  ExprResult ArgExpr(ParseConstantExpression());
-  if (ArgExpr.isInvalid()) {
-    T.skipToEnd();
-    return;
-  }
-  Expr *ExprList = ArgExpr.take();
-  Attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, SourceLocation(), 
-               &ExprList, 1, AttributeList::AS_Declspec);
-
-  T.consumeClose();
-}
-
-/// \brief Determines whether a declspec is a "simple" one requiring no 
-/// arguments.
-bool Parser::IsSimpleMicrosoftDeclSpec(IdentifierInfo *Ident) {
-  return llvm::StringSwitch<bool>(Ident->getName())
-    .Case("dllimport", true)
-    .Case("dllexport", true)
-    .Case("noreturn", true)
-    .Case("nothrow", true)
-    .Case("noinline", true)
-    .Case("naked", true)
-    .Case("appdomain", true)
-    .Case("process", true)
-    .Case("jitintrinsic", true)
-    .Case("noalias", true)
-    .Case("restrict", true)
-    .Case("novtable", true)
-    .Case("selectany", true)
-    .Case("thread", true)
-    .Default(false);
-}
-
-/// \brief Attempts to parse a declspec which is not simple (one that takes 
-/// parameters).  Will return false if we properly handled the declspec, or
-/// true if it is an unknown declspec.
-void Parser::ParseComplexMicrosoftDeclSpec(IdentifierInfo *Ident, 
-                                           SourceLocation Loc,
-                                           ParsedAttributes &Attrs) {
-  // Try to handle the easy case first -- these declspecs all take a single
-  // parameter as their argument.
-  if (llvm::StringSwitch<bool>(Ident->getName())
-      .Case("uuid", true)
-      .Case("align", true)
-      .Case("allocate", true)
-      .Default(false)) {
-    ParseMicrosoftDeclSpecWithSingleArg(Ident, Loc, Attrs);
-  } else if (Ident->getName() == "deprecated") {
-    // The deprecated declspec has an optional single argument, so we will 
-    // check for a l-paren to decide whether we should parse an argument or 
-    // not.
-    if (Tok.getKind() == tok::l_paren)
-      ParseMicrosoftDeclSpecWithSingleArg(Ident, Loc, Attrs);
-    else
-      Attrs.addNew(Ident, Loc, 0, Loc, 0, SourceLocation(), 0, 0, 
-                   AttributeList::AS_Declspec);
-  } else if (Ident->getName() == "property") {
-    // The property declspec is more complex in that it can take one or two
-    // assignment expressions as a parameter, but the lhs of the assignment 
-    // must be named get or put.
-    //
-    // For right now, we will just skip to the closing right paren of the 
-    // property expression.
-    //
-    // FIXME: we should deal with __declspec(property) at some point because it
-    // is used in the platform SDK headers for the Parallel Patterns Library
-    // and ATL.
-    BalancedDelimiterTracker T(*this, tok::l_paren);
-    if (T.expectAndConsume(diag::err_expected_lparen_after, 
-                           Ident->getNameStart(), tok::r_paren))
-      return;
-    T.skipToEnd();
-  } else {
-    // We don't recognize this as a valid declspec, but instead of creating the
-    // attribute and allowing sema to warn about it, we will warn here instead.
-    // This is because some attributes have multiple spellings, but we need to
-    // disallow that for declspecs (such as align vs aligned).  If we made the
-    // attribute, we'd have to split the valid declspec spelling logic into 
-    // both locations.
-    Diag(Loc, diag::warn_ms_declspec_unknown) << Ident;
-
-    // If there's an open paren, we should eat the open and close parens under
-    // the assumption that this unknown declspec has parameters.
-    BalancedDelimiterTracker T(*this, tok::l_paren);
-    if (!T.consumeOpen())
-      T.skipToEnd();
-  }
-}
-
+/// ParseMicrosoftDeclSpec - Parse an __declspec construct
+///
 /// [MS] decl-specifier:
 ///             __declspec ( extended-decl-modifier-seq )
 ///
 /// [MS] extended-decl-modifier-seq:
 ///             extended-decl-modifier[opt]
 ///             extended-decl-modifier extended-decl-modifier-seq
-void Parser::ParseMicrosoftDeclSpec(ParsedAttributes &Attrs) {
+
+void Parser::ParseMicrosoftDeclSpec(ParsedAttributes &attrs) {
   assert(Tok.is(tok::kw___declspec) && "Not a declspec!");
 
   ConsumeToken();
-  BalancedDelimiterTracker T(*this, tok::l_paren);
-  if (T.expectAndConsume(diag::err_expected_lparen_after, "__declspec", 
-                         tok::r_paren))
+  if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
+                       "declspec")) {
+    SkipUntil(tok::r_paren, true); // skip until ) or ;
     return;
-
-  // An empty declspec is perfectly legal and should not warn.  Additionally, 
-  // you can specify multiple attributes per declspec.
-  while (Tok.getKind() != tok::r_paren) {
-    // We expect either a well-known identifier or a generic string.  Anything
-    // else is a malformed declspec.
-    bool IsString = Tok.getKind() == tok::string_literal ? true : false;
-    if (!IsString && Tok.getKind() != tok::identifier && 
-        Tok.getKind() != tok::kw_restrict) {
-      Diag(Tok, diag::err_ms_declspec_type);
-      T.skipToEnd();
-      return;
-    }
-
-    IdentifierInfo *AttrName;
-    SourceLocation AttrNameLoc;
-    if (IsString) {
-      SmallString<8> StrBuffer;
-      bool Invalid = false;
-      StringRef Str = PP.getSpelling(Tok, StrBuffer, &Invalid);
-      if (Invalid) {
-        T.skipToEnd();
-        return;
-      }
-      AttrName = PP.getIdentifierInfo(Str);
-      AttrNameLoc = ConsumeStringToken();
-    } else {
-      AttrName = Tok.getIdentifierInfo();
-      AttrNameLoc = ConsumeToken();
-    }
-  
-    if (IsString || IsSimpleMicrosoftDeclSpec(AttrName))
-      // If we have a generic string, we will allow it because there is no 
-      // documented list of allowable string declspecs, but we know they exist 
-      // (for instance, SAL declspecs in older versions of MSVC).
-      //
-      // Alternatively, if the identifier is a simple one, then it requires no 
-      // arguments and can be turned into an attribute directly.
-      Attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0, SourceLocation(), 
-                   0, 0, AttributeList::AS_Declspec);
-    else
-      ParseComplexMicrosoftDeclSpec(AttrName, AttrNameLoc, Attrs);
   }
-  T.consumeClose();
+
+  while (Tok.getIdentifierInfo()) {
+    IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+    SourceLocation AttrNameLoc = ConsumeToken();
+    
+    // FIXME: Remove this when we have proper __declspec(property()) support.
+    // Just skip everything inside property().
+    if (AttrName->getName() == "property") {
+      ConsumeParen();
+      SkipUntil(tok::r_paren);
+    }
+    if (Tok.is(tok::l_paren)) {
+      ConsumeParen();
+      // FIXME: This doesn't parse __declspec(property(get=get_func_name))
+      // correctly.
+      ExprResult ArgExpr(ParseAssignmentExpression());
+      if (!ArgExpr.isInvalid()) {
+        Expr *ExprList = ArgExpr.take();
+        attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0,
+                     SourceLocation(), &ExprList, 1,
+                     AttributeList::AS_Declspec);
+      }
+      if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
+        SkipUntil(tok::r_paren, false);
+    } else {
+      attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc,
+                   0, SourceLocation(), 0, 0, AttributeList::AS_Declspec);
+    }
+  }
+  if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
+    SkipUntil(tok::r_paren, false);
+  return;
 }
 
 void Parser::ParseMicrosoftTypeAttributes(ParsedAttributes &attrs) {
   // Treat these like attributes
+  // FIXME: Allow Sema to distinguish between these and real attributes!
   while (Tok.is(tok::kw___fastcall) || Tok.is(tok::kw___stdcall) ||
          Tok.is(tok::kw___thiscall) || Tok.is(tok::kw___cdecl)   ||
          Tok.is(tok::kw___ptr64) || Tok.is(tok::kw___w64) ||
@@ -452,7 +346,7 @@
     IdentifierInfo *AttrName = Tok.getIdentifierInfo();
     SourceLocation AttrNameLoc = ConsumeToken();
     attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0,
-                 SourceLocation(), 0, 0, AttributeList::AS_MSTypespec);
+                 SourceLocation(), 0, 0, AttributeList::AS_Declspec);
   }
 }
 
@@ -462,7 +356,7 @@
     IdentifierInfo *AttrName = Tok.getIdentifierInfo();
     SourceLocation AttrNameLoc = ConsumeToken();
     attrs.addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0,
-                 SourceLocation(), 0, 0, AttributeList::AS_MSTypespec);
+                 SourceLocation(), 0, 0, AttributeList::AS_Declspec);
   }
 }
 
@@ -1981,12 +1875,9 @@
 
   ExprVector ArgExprs(Actions);
   ArgExprs.push_back(ArgExpr.release());
-  // FIXME: This should not be GNU, but we since the attribute used is
-  //        based on the spelling, and there is no true spelling for
-  //        C++11 attributes, this isn't accepted.
   Attrs.addNew(PP.getIdentifierInfo("aligned"), KWLoc, 0, KWLoc,
                0, T.getOpenLocation(), ArgExprs.take(), 1,
-               AttributeList::AS_GNU);
+               AttributeList::AS_CXX11);
 }
 
 /// ParseDeclarationSpecifiers
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 6e391c9..b906292 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2902,11 +2902,11 @@
     switch (AttributeList::getKind(AttrName, ScopeName,
                                    AttributeList::AS_CXX11)) {
     // No arguments
-    case AttributeList::AT_CarriesDependency:
+    case AttributeList::AT_carries_dependency:
     // FIXME: implement generic support of attributes with C++11 syntax
     // see Parse/ParseDecl.cpp: ParseGNUAttributes
-    case AttributeList::AT_FallThrough:
-    case AttributeList::AT_NoReturn: {
+    case AttributeList::AT_fallthrough:
+    case AttributeList::AT_noreturn: {
       if (Tok.is(tok::l_paren)) {
         Diag(Tok.getLocation(), diag::err_cxx11_attribute_forbids_arguments)
           << AttrName->getName();
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index c57699b..f6764c2 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -753,7 +753,7 @@
   writtenBS.ModeAttr = false;
   AttributeList* attrs = getAttributes().getList();
   while (attrs) {
-    if (attrs->getKind() == AttributeList::AT_Mode) {
+    if (attrs->getKind() == AttributeList::AT_mode) {
       writtenBS.ModeAttr = true;
       break;
     }
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index fb36c9e..e8682d7 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2894,34 +2894,30 @@
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
     return;
   }
-
+  
   //FIXME: The C++0x version of this attribute has more limited applicabilty
   //       than GNU's, and should error out when it is used to specify a
   //       weaker alignment, rather than being silently ignored.
 
   if (Attr.getNumArgs() == 0) {
-    D->addAttr(::new (S.Context) AlignedAttr(Attr.getRange(), S.Context, 
-               true, 0, Attr.isDeclspecAttribute()));
+    D->addAttr(::new (S.Context) AlignedAttr(Attr.getRange(), S.Context, true, 0));
     return;
   }
 
-  S.AddAlignedAttr(Attr.getRange(), D, Attr.getArg(0), 
-                   Attr.isDeclspecAttribute());
+  S.AddAlignedAttr(Attr.getRange(), D, Attr.getArg(0));
 }
 
-void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, 
-                          bool isDeclSpec) {
+void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E) {
   // FIXME: Handle pack-expansions here.
   if (DiagnoseUnexpandedParameterPack(E))
     return;
 
   if (E->isTypeDependent() || E->isValueDependent()) {
     // Save dependent expressions in the AST to be instantiated.
-    D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, true, E, 
-                                           isDeclSpec));
+    D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, true, E));
     return;
   }
-  
+
   SourceLocation AttrLoc = AttrRange.getBegin();
   // FIXME: Cache the number on the Attr object?
   llvm::APSInt Alignment(32);
@@ -2936,26 +2932,14 @@
       << E->getSourceRange();
     return;
   }
-  if (isDeclSpec) {
-    // We've already verified it's a power of 2, now let's make sure it's
-    // 8192 or less.
-    if (Alignment.getZExtValue() > 8192) {
-      Diag(AttrLoc, diag::err_attribute_aligned_greater_than_8192) 
-        << E->getSourceRange();
-      return;
-    }
-  }
 
-  D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, true, ICE.take(), 
-                                         isDeclSpec));
+  D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, true, ICE.take()));
 }
 
-void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *TS, 
-                          bool isDeclSpec) {
+void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *TS) {
   // FIXME: Cache the number on the Attr object if non-dependent?
   // FIXME: Perform checking of type validity
-  D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, false, TS, 
-                                         isDeclSpec));
+  D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, false, TS));
   return;
 }
 
@@ -3322,22 +3306,22 @@
   }
 
   switch (Attr.getKind()) {
-  case AttributeList::AT_FastCall:
+  case AttributeList::AT_fastcall:
     D->addAttr(::new (S.Context) FastCallAttr(Attr.getRange(), S.Context));
     return;
-  case AttributeList::AT_StdCall:
+  case AttributeList::AT_stdcall:
     D->addAttr(::new (S.Context) StdCallAttr(Attr.getRange(), S.Context));
     return;
-  case AttributeList::AT_ThisCall:
+  case AttributeList::AT_thiscall:
     D->addAttr(::new (S.Context) ThisCallAttr(Attr.getRange(), S.Context));
     return;
-  case AttributeList::AT_CDecl:
+  case AttributeList::AT_cdecl:
     D->addAttr(::new (S.Context) CDeclAttr(Attr.getRange(), S.Context));
     return;
-  case AttributeList::AT_Pascal:
+  case AttributeList::AT_pascal:
     D->addAttr(::new (S.Context) PascalAttr(Attr.getRange(), S.Context));
     return;
-  case AttributeList::AT_Pcs: {
+  case AttributeList::AT_pcs: {
     Expr *Arg = Attr.getArg(0);
     StringLiteral *Str = dyn_cast<StringLiteral>(Arg);
     if (!Str || !Str->isAscii()) {
@@ -3376,7 +3360,7 @@
     return true;
 
   if ((attr.getNumArgs() != 0 &&
-      !(attr.getKind() == AttributeList::AT_Pcs && attr.getNumArgs() == 1)) ||
+      !(attr.getKind() == AttributeList::AT_pcs && attr.getNumArgs() == 1)) ||
       attr.getParameterName()) {
     Diag(attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
     attr.setInvalid();
@@ -3386,12 +3370,12 @@
   // TODO: diagnose uses of these conventions on the wrong target. Or, better
   // move to TargetAttributesSema one day.
   switch (attr.getKind()) {
-  case AttributeList::AT_CDecl: CC = CC_C; break;
-  case AttributeList::AT_FastCall: CC = CC_X86FastCall; break;
-  case AttributeList::AT_StdCall: CC = CC_X86StdCall; break;
-  case AttributeList::AT_ThisCall: CC = CC_X86ThisCall; break;
-  case AttributeList::AT_Pascal: CC = CC_X86Pascal; break;
-  case AttributeList::AT_Pcs: {
+  case AttributeList::AT_cdecl: CC = CC_C; break;
+  case AttributeList::AT_fastcall: CC = CC_X86FastCall; break;
+  case AttributeList::AT_stdcall: CC = CC_X86StdCall; break;
+  case AttributeList::AT_thiscall: CC = CC_X86ThisCall; break;
+  case AttributeList::AT_pascal: CC = CC_X86Pascal; break;
+  case AttributeList::AT_pcs: {
     Expr *Arg = attr.getArg(0);
     StringLiteral *Str = dyn_cast<StringLiteral>(Arg);
     if (!Str || !Str->isAscii()) {
@@ -3542,7 +3526,7 @@
   }
 
   bool typeOK, cf;
-  if (Attr.getKind() == AttributeList::AT_NSConsumed) {
+  if (Attr.getKind() == AttributeList::AT_ns_consumed) {
     typeOK = isValidSubjectOfNSAttribute(S, param->getType());
     cf = false;
   } else {
@@ -3583,7 +3567,7 @@
   else if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
     returnType = PD->getType();
   else if (S.getLangOpts().ObjCAutoRefCount && hasDeclarator(D) &&
-           (Attr.getKind() == AttributeList::AT_NSReturnsRetained))
+           (Attr.getKind() == AttributeList::AT_ns_returns_retained))
     return; // ignore: was handled as a type attribute
   else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
     returnType = FD->getResultType();
@@ -3598,15 +3582,15 @@
   bool cf;
   switch (Attr.getKind()) {
   default: llvm_unreachable("invalid ownership attribute");
-  case AttributeList::AT_NSReturnsAutoreleased:
-  case AttributeList::AT_NSReturnsRetained:
-  case AttributeList::AT_NSReturnsNotRetained:
+  case AttributeList::AT_ns_returns_autoreleased:
+  case AttributeList::AT_ns_returns_retained:
+  case AttributeList::AT_ns_returns_not_retained:
     typeOK = isValidSubjectOfNSAttribute(S, returnType);
     cf = false;
     break;
 
-  case AttributeList::AT_CFReturnsRetained:
-  case AttributeList::AT_CFReturnsNotRetained:
+  case AttributeList::AT_cf_returns_retained:
+  case AttributeList::AT_cf_returns_not_retained:
     typeOK = isValidSubjectOfCFAttribute(S, returnType);
     cf = true;
     break;
@@ -3621,23 +3605,23 @@
   switch (Attr.getKind()) {
     default:
       llvm_unreachable("invalid ownership attribute");
-    case AttributeList::AT_NSReturnsAutoreleased:
+    case AttributeList::AT_ns_returns_autoreleased:
       D->addAttr(::new (S.Context) NSReturnsAutoreleasedAttr(Attr.getRange(),
                                                              S.Context));
       return;
-    case AttributeList::AT_CFReturnsNotRetained:
+    case AttributeList::AT_cf_returns_not_retained:
       D->addAttr(::new (S.Context) CFReturnsNotRetainedAttr(Attr.getRange(),
                                                             S.Context));
       return;
-    case AttributeList::AT_NSReturnsNotRetained:
+    case AttributeList::AT_ns_returns_not_retained:
       D->addAttr(::new (S.Context) NSReturnsNotRetainedAttr(Attr.getRange(),
                                                             S.Context));
       return;
-    case AttributeList::AT_CFReturnsRetained:
+    case AttributeList::AT_cf_returns_retained:
       D->addAttr(::new (S.Context) CFReturnsRetainedAttr(Attr.getRange(),
                                                          S.Context));
       return;
-    case AttributeList::AT_NSReturnsRetained:
+    case AttributeList::AT_ns_returns_retained:
       D->addAttr(::new (S.Context) NSReturnsRetainedAttr(Attr.getRange(),
                                                          S.Context));
       return;
@@ -3681,7 +3665,7 @@
     return;
   }
 
-  bool IsAudited = (A.getKind() == AttributeList::AT_CFAuditedTransfer);
+  bool IsAudited = (A.getKind() == AttributeList::AT_cf_audited_transfer);
 
   // Check whether there's a conflicting attribute already present.
   Attr *Existing;
@@ -3792,6 +3776,22 @@
                  ObjCPreciseLifetimeAttr(Attr.getRange(), S.Context));
 }
 
+static bool isKnownDeclSpecAttr(const AttributeList &Attr) {
+  switch (Attr.getKind()) {
+  default:
+    return false;
+  case AttributeList::AT_dllimport:
+  case AttributeList::AT_dllexport:
+  case AttributeList::AT_uuid:
+  case AttributeList::AT_deprecated:
+  case AttributeList::AT_noreturn:
+  case AttributeList::AT_nothrow:
+  case AttributeList::AT_naked:
+  case AttributeList::AT_noinline:
+    return true;
+  }
+}
+
 //===----------------------------------------------------------------------===//
 // Microsoft specific attribute handlers.
 //===----------------------------------------------------------------------===//
@@ -3853,13 +3853,13 @@
 static void handleInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   if (S.LangOpts.MicrosoftExt) {
     AttributeList::Kind Kind = Attr.getKind();
-    if (Kind == AttributeList::AT_SingleInheritance)
+    if (Kind == AttributeList::AT_single_inheritance)
       D->addAttr(
           ::new (S.Context) SingleInheritanceAttr(Attr.getRange(), S.Context));
-    else if (Kind == AttributeList::AT_MultipleInheritance)
+    else if (Kind == AttributeList::AT_multiple_inheritance)
       D->addAttr(
           ::new (S.Context) MultipleInheritanceAttr(Attr.getRange(), S.Context));
-    else if (Kind == AttributeList::AT_VirtualInheritance)
+    else if (Kind == AttributeList::AT_virtual_inheritance)
       D->addAttr(
           ::new (S.Context) VirtualInheritanceAttr(Attr.getRange(), S.Context));
   } else
@@ -3869,13 +3869,13 @@
 static void handlePortabilityAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   if (S.LangOpts.MicrosoftExt) {
     AttributeList::Kind Kind = Attr.getKind();
-    if (Kind == AttributeList::AT_Ptr32)
+    if (Kind == AttributeList::AT_ptr32)
       D->addAttr(
           ::new (S.Context) Ptr32Attr(Attr.getRange(), S.Context));
-    else if (Kind == AttributeList::AT_Ptr64)
+    else if (Kind == AttributeList::AT_ptr64)
       D->addAttr(
           ::new (S.Context) Ptr64Attr(Attr.getRange(), S.Context));
-    else if (Kind == AttributeList::AT_Win64)
+    else if (Kind == AttributeList::AT_w64)
       D->addAttr(
           ::new (S.Context) Win64Attr(Attr.getRange(), S.Context));
   } else
@@ -3896,9 +3896,9 @@
 static void ProcessNonInheritableDeclAttr(Sema &S, Scope *scope, Decl *D,
                                           const AttributeList &Attr) {
   switch (Attr.getKind()) {
-  case AttributeList::AT_CUDADevice:  handleDeviceAttr      (S, D, Attr); break;
-  case AttributeList::AT_CUDAHost:    handleHostAttr        (S, D, Attr); break;
-  case AttributeList::AT_Overloadable:handleOverloadableAttr(S, D, Attr); break;
+  case AttributeList::AT_device:      handleDeviceAttr      (S, D, Attr); break;
+  case AttributeList::AT_host:        handleHostAttr        (S, D, Attr); break;
+  case AttributeList::AT_overloadable:handleOverloadableAttr(S, D, Attr); break;
   default:
     break;
   }
@@ -3907,242 +3907,242 @@
 static void ProcessInheritableDeclAttr(Sema &S, Scope *scope, Decl *D,
                                        const AttributeList &Attr) {
   switch (Attr.getKind()) {
-    case AttributeList::AT_IBAction:          handleIBAction(S, D, Attr); break;
-    case AttributeList::AT_IBOutlet:          handleIBOutlet(S, D, Attr); break;
-    case AttributeList::AT_IBOutletCollection:
+    case AttributeList::AT_ibaction:            handleIBAction(S, D, Attr); break;
+    case AttributeList::AT_iboutlet:          handleIBOutlet(S, D, Attr); break;
+    case AttributeList::AT_iboutletcollection:
       handleIBOutletCollection(S, D, Attr); break;
-  case AttributeList::AT_AddressSpace:
-  case AttributeList::AT_OpenCLImageAccess:
-  case AttributeList::AT_ObjCGC:
-  case AttributeList::AT_VectorSize:
-  case AttributeList::AT_NeonVectorType:
-  case AttributeList::AT_NeonPolyVectorType:
+  case AttributeList::AT_address_space:
+  case AttributeList::AT_opencl_image_access:
+  case AttributeList::AT_objc_gc:
+  case AttributeList::AT_vector_size:
+  case AttributeList::AT_neon_vector_type:
+  case AttributeList::AT_neon_polyvector_type:
     // Ignore these, these are type attributes, handled by
     // ProcessTypeAttributes.
     break;
-  case AttributeList::AT_CUDADevice:
-  case AttributeList::AT_CUDAHost:
-  case AttributeList::AT_Overloadable:
+  case AttributeList::AT_device:
+  case AttributeList::AT_host:
+  case AttributeList::AT_overloadable:
     // Ignore, this is a non-inheritable attribute, handled
     // by ProcessNonInheritableDeclAttr.
     break;
-  case AttributeList::AT_Alias:       handleAliasAttr       (S, D, Attr); break;
-  case AttributeList::AT_Aligned:     handleAlignedAttr     (S, D, Attr); break;
-  case AttributeList::AT_AllocSize:   handleAllocSizeAttr   (S, D, Attr); break;
-  case AttributeList::AT_AlwaysInline:
+  case AttributeList::AT_alias:       handleAliasAttr       (S, D, Attr); break;
+  case AttributeList::AT_aligned:     handleAlignedAttr     (S, D, Attr); break;
+  case AttributeList::AT_alloc_size:  handleAllocSizeAttr   (S, D, Attr); break;
+  case AttributeList::AT_always_inline:
     handleAlwaysInlineAttr  (S, D, Attr); break;
-  case AttributeList::AT_AnalyzerNoReturn:
+  case AttributeList::AT_analyzer_noreturn:
     handleAnalyzerNoReturnAttr  (S, D, Attr); break;
-  case AttributeList::AT_Annotate:    handleAnnotateAttr    (S, D, Attr); break;
-  case AttributeList::AT_Availability:handleAvailabilityAttr(S, D, Attr); break;
-  case AttributeList::AT_CarriesDependency:
+  case AttributeList::AT_annotate:    handleAnnotateAttr    (S, D, Attr); break;
+  case AttributeList::AT_availability:handleAvailabilityAttr(S, D, Attr); break;
+  case AttributeList::AT_carries_dependency:
                                       handleDependencyAttr  (S, D, Attr); break;
-  case AttributeList::AT_Common:      handleCommonAttr      (S, D, Attr); break;
-  case AttributeList::AT_CUDAConstant:handleConstantAttr    (S, D, Attr); break;
-  case AttributeList::AT_Constructor: handleConstructorAttr (S, D, Attr); break;
-  case AttributeList::AT_Deprecated:
+  case AttributeList::AT_common:      handleCommonAttr      (S, D, Attr); break;
+  case AttributeList::AT_constant:    handleConstantAttr    (S, D, Attr); break;
+  case AttributeList::AT_constructor: handleConstructorAttr (S, D, Attr); break;
+  case AttributeList::AT_deprecated:
     handleAttrWithMessage<DeprecatedAttr>(S, D, Attr, "deprecated");
     break;
-  case AttributeList::AT_Destructor:  handleDestructorAttr  (S, D, Attr); break;
-  case AttributeList::AT_ExtVectorType:
+  case AttributeList::AT_destructor:  handleDestructorAttr  (S, D, Attr); break;
+  case AttributeList::AT_ext_vector_type:
     handleExtVectorTypeAttr(S, scope, D, Attr);
     break;
-  case AttributeList::AT_Format:      handleFormatAttr      (S, D, Attr); break;
-  case AttributeList::AT_FormatArg:   handleFormatArgAttr   (S, D, Attr); break;
-  case AttributeList::AT_CUDAGlobal:  handleGlobalAttr      (S, D, Attr); break;
-  case AttributeList::AT_GNUInline:   handleGNUInlineAttr   (S, D, Attr); break;
-  case AttributeList::AT_CUDALaunchBounds:
+  case AttributeList::AT_format:      handleFormatAttr      (S, D, Attr); break;
+  case AttributeList::AT_format_arg:  handleFormatArgAttr   (S, D, Attr); break;
+  case AttributeList::AT_global:      handleGlobalAttr      (S, D, Attr); break;
+  case AttributeList::AT_gnu_inline:  handleGNUInlineAttr   (S, D, Attr); break;
+  case AttributeList::AT_launch_bounds:
     handleLaunchBoundsAttr(S, D, Attr);
     break;
-  case AttributeList::AT_Mode:        handleModeAttr        (S, D, Attr); break;
-  case AttributeList::AT_Malloc:      handleMallocAttr      (S, D, Attr); break;
-  case AttributeList::AT_MayAlias:    handleMayAliasAttr    (S, D, Attr); break;
-  case AttributeList::AT_NoCommon:    handleNoCommonAttr    (S, D, Attr); break;
-  case AttributeList::AT_NonNull:     handleNonNullAttr     (S, D, Attr); break;
+  case AttributeList::AT_mode:        handleModeAttr        (S, D, Attr); break;
+  case AttributeList::AT_malloc:      handleMallocAttr      (S, D, Attr); break;
+  case AttributeList::AT_may_alias:   handleMayAliasAttr    (S, D, Attr); break;
+  case AttributeList::AT_nocommon:    handleNoCommonAttr    (S, D, Attr); break;
+  case AttributeList::AT_nonnull:     handleNonNullAttr     (S, D, Attr); break;
   case AttributeList::AT_ownership_returns:
   case AttributeList::AT_ownership_takes:
   case AttributeList::AT_ownership_holds:
       handleOwnershipAttr     (S, D, Attr); break;
-  case AttributeList::AT_Cold:        handleColdAttr        (S, D, Attr); break;
-  case AttributeList::AT_Hot:         handleHotAttr         (S, D, Attr); break;
-  case AttributeList::AT_Naked:       handleNakedAttr       (S, D, Attr); break;
-  case AttributeList::AT_NoReturn:    handleNoReturnAttr    (S, D, Attr); break;
-  case AttributeList::AT_NoThrow:     handleNothrowAttr     (S, D, Attr); break;
-  case AttributeList::AT_CUDAShared:  handleSharedAttr      (S, D, Attr); break;
-  case AttributeList::AT_VecReturn:   handleVecReturnAttr   (S, D, Attr); break;
+  case AttributeList::AT_cold:        handleColdAttr        (S, D, Attr); break;
+  case AttributeList::AT_hot:         handleHotAttr         (S, D, Attr); break;
+  case AttributeList::AT_naked:       handleNakedAttr       (S, D, Attr); break;
+  case AttributeList::AT_noreturn:    handleNoReturnAttr    (S, D, Attr); break;
+  case AttributeList::AT_nothrow:     handleNothrowAttr     (S, D, Attr); break;
+  case AttributeList::AT_shared:      handleSharedAttr      (S, D, Attr); break;
+  case AttributeList::AT_vecreturn:   handleVecReturnAttr   (S, D, Attr); break;
 
-  case AttributeList::AT_ObjCOwnership:
+  case AttributeList::AT_objc_ownership:
     handleObjCOwnershipAttr(S, D, Attr); break;
-  case AttributeList::AT_ObjCPreciseLifetime:
+  case AttributeList::AT_objc_precise_lifetime:
     handleObjCPreciseLifetimeAttr(S, D, Attr); break;
 
-  case AttributeList::AT_ObjCReturnsInnerPointer:
+  case AttributeList::AT_objc_returns_inner_pointer:
     handleObjCReturnsInnerPointerAttr(S, D, Attr); break;
 
-  case AttributeList::AT_NSBridged:
+  case AttributeList::AT_ns_bridged:
     handleNSBridgedAttr(S, scope, D, Attr); break;
 
-  case AttributeList::AT_CFAuditedTransfer:
-  case AttributeList::AT_CFUnknownTransfer:
+  case AttributeList::AT_cf_audited_transfer:
+  case AttributeList::AT_cf_unknown_transfer:
     handleCFTransferAttr(S, D, Attr); break;
 
   // Checker-specific.
-  case AttributeList::AT_CFConsumed:
-  case AttributeList::AT_NSConsumed:  handleNSConsumedAttr  (S, D, Attr); break;
-  case AttributeList::AT_NSConsumesSelf:
+  case AttributeList::AT_cf_consumed:
+  case AttributeList::AT_ns_consumed: handleNSConsumedAttr  (S, D, Attr); break;
+  case AttributeList::AT_ns_consumes_self:
     handleNSConsumesSelfAttr(S, D, Attr); break;
 
-  case AttributeList::AT_NSReturnsAutoreleased:
-  case AttributeList::AT_NSReturnsNotRetained:
-  case AttributeList::AT_CFReturnsNotRetained:
-  case AttributeList::AT_NSReturnsRetained:
-  case AttributeList::AT_CFReturnsRetained:
+  case AttributeList::AT_ns_returns_autoreleased:
+  case AttributeList::AT_ns_returns_not_retained:
+  case AttributeList::AT_cf_returns_not_retained:
+  case AttributeList::AT_ns_returns_retained:
+  case AttributeList::AT_cf_returns_retained:
     handleNSReturnsRetainedAttr(S, D, Attr); break;
 
-  case AttributeList::AT_ReqdWorkGroupSize:
+  case AttributeList::AT_reqd_work_group_size:
     handleReqdWorkGroupSize(S, D, Attr); break;
 
-  case AttributeList::AT_InitPriority: 
+  case AttributeList::AT_init_priority: 
       handleInitPriorityAttr(S, D, Attr); break;
       
-  case AttributeList::AT_Packed:      handlePackedAttr      (S, D, Attr); break;
-  case AttributeList::AT_Section:     handleSectionAttr     (S, D, Attr); break;
-  case AttributeList::AT_Unavailable:
+  case AttributeList::AT_packed:      handlePackedAttr      (S, D, Attr); break;
+  case AttributeList::AT_section:     handleSectionAttr     (S, D, Attr); break;
+  case AttributeList::AT_unavailable:
     handleAttrWithMessage<UnavailableAttr>(S, D, Attr, "unavailable");
     break;
-  case AttributeList::AT_ArcWeakrefUnavailable: 
+  case AttributeList::AT_objc_arc_weak_reference_unavailable: 
     handleArcWeakrefUnavailableAttr (S, D, Attr); 
     break;
-  case AttributeList::AT_ObjCRootClass:
+  case AttributeList::AT_objc_root_class:
     handleObjCRootClassAttr(S, D, Attr);
     break;
-  case AttributeList::AT_ObjCRequiresPropertyDefs: 
+  case AttributeList::AT_objc_requires_property_definitions: 
     handleObjCRequiresPropertyDefsAttr (S, D, Attr); 
     break;
-  case AttributeList::AT_Unused:      handleUnusedAttr      (S, D, Attr); break;
-  case AttributeList::AT_ReturnsTwice:
+  case AttributeList::AT_unused:      handleUnusedAttr      (S, D, Attr); break;
+  case AttributeList::AT_returns_twice:
     handleReturnsTwiceAttr(S, D, Attr);
     break;
-  case AttributeList::AT_Used:        handleUsedAttr        (S, D, Attr); break;
-  case AttributeList::AT_Visibility:  handleVisibilityAttr  (S, D, Attr); break;
-  case AttributeList::AT_WarnUnusedResult: handleWarnUnusedResult(S, D, Attr);
+  case AttributeList::AT_used:        handleUsedAttr        (S, D, Attr); break;
+  case AttributeList::AT_visibility:  handleVisibilityAttr  (S, D, Attr); break;
+  case AttributeList::AT_warn_unused_result: handleWarnUnusedResult(S, D, Attr);
     break;
-  case AttributeList::AT_Weak:        handleWeakAttr        (S, D, Attr); break;
-  case AttributeList::AT_WeakRef:     handleWeakRefAttr     (S, D, Attr); break;
-  case AttributeList::AT_WeakImport:  handleWeakImportAttr  (S, D, Attr); break;
-  case AttributeList::AT_TransparentUnion:
+  case AttributeList::AT_weak:        handleWeakAttr        (S, D, Attr); break;
+  case AttributeList::AT_weakref:     handleWeakRefAttr     (S, D, Attr); break;
+  case AttributeList::AT_weak_import: handleWeakImportAttr  (S, D, Attr); break;
+  case AttributeList::AT_transparent_union:
     handleTransparentUnionAttr(S, D, Attr);
     break;
-  case AttributeList::AT_ObjCException:
+  case AttributeList::AT_objc_exception:
     handleObjCExceptionAttr(S, D, Attr);
     break;
-  case AttributeList::AT_ObjCMethodFamily:
+  case AttributeList::AT_objc_method_family:
     handleObjCMethodFamilyAttr(S, D, Attr);
     break;
-  case AttributeList::AT_ObjCNSObject:handleObjCNSObject    (S, D, Attr); break;
-  case AttributeList::AT_Blocks:      handleBlocksAttr      (S, D, Attr); break;
-  case AttributeList::AT_Sentinel:    handleSentinelAttr    (S, D, Attr); break;
-  case AttributeList::AT_Const:       handleConstAttr       (S, D, Attr); break;
-  case AttributeList::AT_Pure:        handlePureAttr        (S, D, Attr); break;
-  case AttributeList::AT_Cleanup:     handleCleanupAttr     (S, D, Attr); break;
-  case AttributeList::AT_NoDebug:     handleNoDebugAttr     (S, D, Attr); break;
-  case AttributeList::AT_NoInline:    handleNoInlineAttr    (S, D, Attr); break;
-  case AttributeList::AT_Regparm:     handleRegparmAttr     (S, D, Attr); break;
+  case AttributeList::AT_NSObject:    handleObjCNSObject    (S, D, Attr); break;
+  case AttributeList::AT_blocks:      handleBlocksAttr      (S, D, Attr); break;
+  case AttributeList::AT_sentinel:    handleSentinelAttr    (S, D, Attr); break;
+  case AttributeList::AT_const:       handleConstAttr       (S, D, Attr); break;
+  case AttributeList::AT_pure:        handlePureAttr        (S, D, Attr); break;
+  case AttributeList::AT_cleanup:     handleCleanupAttr     (S, D, Attr); break;
+  case AttributeList::AT_nodebug:     handleNoDebugAttr     (S, D, Attr); break;
+  case AttributeList::AT_noinline:    handleNoInlineAttr    (S, D, Attr); break;
+  case AttributeList::AT_regparm:     handleRegparmAttr     (S, D, Attr); break;
   case AttributeList::IgnoredAttribute:
     // Just ignore
     break;
-  case AttributeList::AT_NoInstrumentFunction:  // Interacts with -pg.
+  case AttributeList::AT_no_instrument_function:  // Interacts with -pg.
     handleNoInstrumentFunctionAttr(S, D, Attr);
     break;
-  case AttributeList::AT_StdCall:
-  case AttributeList::AT_CDecl:
-  case AttributeList::AT_FastCall:
-  case AttributeList::AT_ThisCall:
-  case AttributeList::AT_Pascal:
-  case AttributeList::AT_Pcs:
+  case AttributeList::AT_stdcall:
+  case AttributeList::AT_cdecl:
+  case AttributeList::AT_fastcall:
+  case AttributeList::AT_thiscall:
+  case AttributeList::AT_pascal:
+  case AttributeList::AT_pcs:
     handleCallConvAttr(S, D, Attr);
     break;
-  case AttributeList::AT_OpenCLKernel:
+  case AttributeList::AT_opencl_kernel_function:
     handleOpenCLKernelAttr(S, D, Attr);
     break;
 
   // Microsoft attributes:
-  case AttributeList::AT_MsStruct:
+  case AttributeList::AT_ms_struct:
     handleMsStructAttr(S, D, Attr);
     break;
-  case AttributeList::AT_Uuid:
+  case AttributeList::AT_uuid:
     handleUuidAttr(S, D, Attr);
     break;
-  case AttributeList::AT_SingleInheritance:
-  case AttributeList::AT_MultipleInheritance:
-  case AttributeList::AT_VirtualInheritance:
+  case AttributeList::AT_single_inheritance:
+  case AttributeList::AT_multiple_inheritance:
+  case AttributeList::AT_virtual_inheritance:
     handleInheritanceAttr(S, D, Attr);
     break;
-  case AttributeList::AT_Win64:
-  case AttributeList::AT_Ptr32:
-  case AttributeList::AT_Ptr64:
+  case AttributeList::AT_w64:
+  case AttributeList::AT_ptr32:
+  case AttributeList::AT_ptr64:
     handlePortabilityAttr(S, D, Attr);
     break;
-  case AttributeList::AT_ForceInline:
+  case AttributeList::AT_forceinline:
     handleForceInlineAttr(S, D, Attr);
     break;
 
   // Thread safety attributes:
-  case AttributeList::AT_GuardedVar:
+  case AttributeList::AT_guarded_var:
     handleGuardedVarAttr(S, D, Attr);
     break;
-  case AttributeList::AT_PtGuardedVar:
+  case AttributeList::AT_pt_guarded_var:
     handleGuardedVarAttr(S, D, Attr, /*pointer = */true);
     break;
-  case AttributeList::AT_ScopedLockable:
+  case AttributeList::AT_scoped_lockable:
     handleLockableAttr(S, D, Attr, /*scoped = */true);
     break;
-  case AttributeList::AT_NoAddressSafetyAnalysis:
+  case AttributeList::AT_no_address_safety_analysis:
     handleNoAddressSafetyAttr(S, D, Attr);
     break;
-  case AttributeList::AT_NoThreadSafetyAnalysis:
+  case AttributeList::AT_no_thread_safety_analysis:
     handleNoThreadSafetyAttr(S, D, Attr);
     break;
-  case AttributeList::AT_Lockable:
+  case AttributeList::AT_lockable:
     handleLockableAttr(S, D, Attr);
     break;
-  case AttributeList::AT_GuardedBy:
+  case AttributeList::AT_guarded_by:
     handleGuardedByAttr(S, D, Attr);
     break;
-  case AttributeList::AT_PtGuardedBy:
+  case AttributeList::AT_pt_guarded_by:
     handleGuardedByAttr(S, D, Attr, /*pointer = */true);
     break;
-  case AttributeList::AT_ExclusiveLockFunction:
+  case AttributeList::AT_exclusive_lock_function:
     handleLockFunAttr(S, D, Attr, /*exclusive = */true);
     break;
-  case AttributeList::AT_ExclusiveLocksRequired:
+  case AttributeList::AT_exclusive_locks_required:
     handleLocksRequiredAttr(S, D, Attr, /*exclusive = */true);
     break;
-  case AttributeList::AT_ExclusiveTrylockFunction:
+  case AttributeList::AT_exclusive_trylock_function:
     handleTrylockFunAttr(S, D, Attr, /*exclusive = */true);
     break;
-  case AttributeList::AT_LockReturned:
+  case AttributeList::AT_lock_returned:
     handleLockReturnedAttr(S, D, Attr);
     break;
-  case AttributeList::AT_LocksExcluded:
+  case AttributeList::AT_locks_excluded:
     handleLocksExcludedAttr(S, D, Attr);
     break;
-  case AttributeList::AT_SharedLockFunction:
+  case AttributeList::AT_shared_lock_function:
     handleLockFunAttr(S, D, Attr);
     break;
-  case AttributeList::AT_SharedLocksRequired:
+  case AttributeList::AT_shared_locks_required:
     handleLocksRequiredAttr(S, D, Attr);
     break;
-  case AttributeList::AT_SharedTrylockFunction:
+  case AttributeList::AT_shared_trylock_function:
     handleTrylockFunAttr(S, D, Attr);
     break;
-  case AttributeList::AT_UnlockFunction:
+  case AttributeList::AT_unlock_function:
     handleUnlockFunAttr(S, D, Attr);
     break;
-  case AttributeList::AT_AcquiredBefore:
+  case AttributeList::AT_acquired_before:
     handleAcquireOrderAttr(S, D, Attr, /*before = */true);
     break;
-  case AttributeList::AT_AcquiredAfter:
+  case AttributeList::AT_acquired_after:
     handleAcquireOrderAttr(S, D, Attr, /*before = */false);
     break;
 
@@ -4150,9 +4150,8 @@
     // Ask target about the attribute.
     const TargetAttributesSema &TargetAttrs = S.getTargetAttributesSema();
     if (!TargetAttrs.ProcessDeclAttribute(scope, D, Attr, S))
-      S.Diag(Attr.getLoc(), Attr.isDeclspecAttribute() ? 
-             diag::warn_unhandled_ms_attribute_ignored : 
-             diag::warn_unknown_attribute_ignored) << Attr.getName();
+      S.Diag(Attr.getLoc(), diag::warn_unknown_attribute_ignored)
+        << Attr.getName();
     break;
   }
 }
@@ -4167,11 +4166,8 @@
   if (Attr.isInvalid())
     return;
 
-  // Type attributes are still treated as declaration attributes by 
-  // ParseMicrosoftTypeAttributes and ParseBorlandTypeAttributes.  We don't 
-  // want to process them, however, because we will simply warn about ignoring 
-  // them.  So instead, we will bail out early.
-  if (Attr.isMSTypespecAttribute())
+  if (Attr.isDeclspecAttribute() && !isKnownDeclSpecAttr(Attr))
+    // FIXME: Try to deal with other __declspec attributes!
     return;
 
   if (NonInheritable)
@@ -4205,7 +4201,7 @@
 bool Sema::ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl,
                                           const AttributeList *AttrList) {
   for (const AttributeList* l = AttrList; l; l = l->getNext()) {
-    if (l->getKind() == AttributeList::AT_Annotate) {
+    if (l->getKind() == AttributeList::AT_annotate) {
       handleAnnotateAttr(*this, ASDecl, *l);
     } else {
       Diag(l->getLoc(), diag::err_only_annotate_after_access_spec);
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 395b9d6..60b2d1e 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -48,7 +48,7 @@
 static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const AttributeList &A,
                                   SourceRange Range) {
   switch (A.getKind()) {
-  case AttributeList::AT_FallThrough:
+  case AttributeList::AT_fallthrough:
     return handleFallThroughAttr(S, St, A, Range);
   default:
     // if we're here, then we parsed an attribute, but didn't recognize it as a
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d4b5ffe..662b302 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -79,16 +79,14 @@
           ExprResult Result = SubstExpr(Aligned->getAlignmentExpr(),
                                         TemplateArgs);
           if (!Result.isInvalid())
-            AddAlignedAttr(Aligned->getLocation(), New, Result.takeAs<Expr>(), 
-                           Aligned->getIsMSDeclSpec());
+            AddAlignedAttr(Aligned->getLocation(), New, Result.takeAs<Expr>());
         } else {
           TypeSourceInfo *Result = SubstType(Aligned->getAlignmentType(),
                                              TemplateArgs,
                                              Aligned->getLocation(),
                                              DeclarationName());
           if (Result)
-            AddAlignedAttr(Aligned->getLocation(), New, Result, 
-                           Aligned->getIsMSDeclSpec());
+            AddAlignedAttr(Aligned->getLocation(), New, Result);
         }
         continue;
       }
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index d6c8d92..0bdf75b 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -59,12 +59,12 @@
 
   unsigned diagID = 0;
   switch (attr.getKind()) {
-  case AttributeList::AT_ObjCGC:
+  case AttributeList::AT_objc_gc:
     diagID = diag::warn_pointer_attribute_wrong_type;
     useExpansionLoc = true;
     break;
 
-  case AttributeList::AT_ObjCOwnership:
+  case AttributeList::AT_objc_ownership:
     diagID = diag::warn_objc_object_attribute_wrong_type;
     useExpansionLoc = true;
     break;
@@ -93,19 +93,19 @@
 // objc_gc applies to Objective-C pointers or, otherwise, to the
 // smallest available pointer type (i.e. 'void*' in 'void**').
 #define OBJC_POINTER_TYPE_ATTRS_CASELIST \
-    case AttributeList::AT_ObjCGC: \
-    case AttributeList::AT_ObjCOwnership
+    case AttributeList::AT_objc_gc: \
+    case AttributeList::AT_objc_ownership
 
 // Function type attributes.
 #define FUNCTION_TYPE_ATTRS_CASELIST \
-    case AttributeList::AT_NoReturn: \
-    case AttributeList::AT_CDecl: \
-    case AttributeList::AT_FastCall: \
-    case AttributeList::AT_StdCall: \
-    case AttributeList::AT_ThisCall: \
-    case AttributeList::AT_Pascal: \
-    case AttributeList::AT_Regparm: \
-    case AttributeList::AT_Pcs \
+    case AttributeList::AT_noreturn: \
+    case AttributeList::AT_cdecl: \
+    case AttributeList::AT_fastcall: \
+    case AttributeList::AT_stdcall: \
+    case AttributeList::AT_thiscall: \
+    case AttributeList::AT_pascal: \
+    case AttributeList::AT_regparm: \
+    case AttributeList::AT_pcs \
 
 namespace {
   /// An object which stores processing state for the entire
@@ -284,9 +284,9 @@
 
 static bool handleObjCPointerTypeAttr(TypeProcessingState &state,
                                       AttributeList &attr, QualType &type) {
-  if (attr.getKind() == AttributeList::AT_ObjCGC)
+  if (attr.getKind() == AttributeList::AT_objc_gc)
     return handleObjCGCTypeAttr(state, attr, type);
-  assert(attr.getKind() == AttributeList::AT_ObjCOwnership);
+  assert(attr.getKind() == AttributeList::AT_objc_ownership);
   return handleObjCOwnershipTypeAttr(state, attr, type);
 }
 
@@ -505,7 +505,7 @@
       distributeObjCPointerTypeAttrFromDeclarator(state, *attr, declSpecType);
       break;
 
-    case AttributeList::AT_NSReturnsRetained:
+    case AttributeList::AT_ns_returns_retained:
       if (!state.getSema().getLangOpts().ObjCAutoRefCount)
         break;
       // fallthrough
@@ -1719,7 +1719,7 @@
       return;
     for (const AttributeList *attr = chunk.getAttrs(); attr;
            attr = attr->getNext())
-      if (attr->getKind() == AttributeList::AT_ObjCOwnership)
+      if (attr->getKind() == AttributeList::AT_objc_ownership)
         return;
 
     transferARCOwnershipToDeclaratorChunk(state, Qualifiers::OCL_Autoreleasing,
@@ -2280,7 +2280,7 @@
           bool Overloadable = false;
           for (const AttributeList *Attrs = D.getAttributes();
                Attrs; Attrs = Attrs->getNext()) {
-            if (Attrs->getKind() == AttributeList::AT_Overloadable) {
+            if (Attrs->getKind() == AttributeList::AT_overloadable) {
               Overloadable = true;
               break;
             }
@@ -2710,7 +2710,7 @@
   DeclaratorChunk &chunk = D.getTypeObject(chunkIndex);
   for (const AttributeList *attr = chunk.getAttrs(); attr;
          attr = attr->getNext())
-    if (attr->getKind() == AttributeList::AT_ObjCOwnership)
+    if (attr->getKind() == AttributeList::AT_objc_ownership)
       return;
 
   const char *attrStr = 0;
@@ -2806,33 +2806,33 @@
 static AttributeList::Kind getAttrListKind(AttributedType::Kind kind) {
   switch (kind) {
   case AttributedType::attr_address_space:
-    return AttributeList::AT_AddressSpace;
+    return AttributeList::AT_address_space;
   case AttributedType::attr_regparm:
-    return AttributeList::AT_Regparm;
+    return AttributeList::AT_regparm;
   case AttributedType::attr_vector_size:
-    return AttributeList::AT_VectorSize;
+    return AttributeList::AT_vector_size;
   case AttributedType::attr_neon_vector_type:
-    return AttributeList::AT_NeonVectorType;
+    return AttributeList::AT_neon_vector_type;
   case AttributedType::attr_neon_polyvector_type:
-    return AttributeList::AT_NeonPolyVectorType;
+    return AttributeList::AT_neon_polyvector_type;
   case AttributedType::attr_objc_gc:
-    return AttributeList::AT_ObjCGC;
+    return AttributeList::AT_objc_gc;
   case AttributedType::attr_objc_ownership:
-    return AttributeList::AT_ObjCOwnership;
+    return AttributeList::AT_objc_ownership;
   case AttributedType::attr_noreturn:
-    return AttributeList::AT_NoReturn;
+    return AttributeList::AT_noreturn;
   case AttributedType::attr_cdecl:
-    return AttributeList::AT_CDecl;
+    return AttributeList::AT_cdecl;
   case AttributedType::attr_fastcall:
-    return AttributeList::AT_FastCall;
+    return AttributeList::AT_fastcall;
   case AttributedType::attr_stdcall:
-    return AttributeList::AT_StdCall;
+    return AttributeList::AT_stdcall;
   case AttributedType::attr_thiscall:
-    return AttributeList::AT_ThisCall;
+    return AttributeList::AT_thiscall;
   case AttributedType::attr_pascal:
-    return AttributeList::AT_Pascal;
+    return AttributeList::AT_pascal;
   case AttributedType::attr_pcs:
-    return AttributeList::AT_Pcs;
+    return AttributeList::AT_pcs;
   }
   llvm_unreachable("unexpected attribute kind!");
 }
@@ -3667,7 +3667,7 @@
 
   FunctionTypeUnwrapper unwrapped(S, type);
 
-  if (attr.getKind() == AttributeList::AT_NoReturn) {
+  if (attr.getKind() == AttributeList::AT_noreturn) {
     if (S.CheckNoReturnAttr(attr))
       return true;
 
@@ -3683,7 +3683,7 @@
 
   // ns_returns_retained is not always a type attribute, but if we got
   // here, we're treating it as one right now.
-  if (attr.getKind() == AttributeList::AT_NSReturnsRetained) {
+  if (attr.getKind() == AttributeList::AT_ns_returns_retained) {
     assert(S.getLangOpts().ObjCAutoRefCount &&
            "ns_returns_retained treated as type attribute in non-ARC");
     if (attr.getNumArgs()) return true;
@@ -3698,7 +3698,7 @@
     return true;
   }
 
-  if (attr.getKind() == AttributeList::AT_Regparm) {
+  if (attr.getKind() == AttributeList::AT_regparm) {
     unsigned value;
     if (S.CheckRegparmAttr(attr, value))
       return true;
@@ -3986,12 +3986,12 @@
     switch (attr.getKind()) {
     default: break;
 
-    case AttributeList::AT_MayAlias:
+    case AttributeList::AT_may_alias:
       // FIXME: This attribute needs to actually be handled, but if we ignore
       // it it breaks large amounts of Linux software.
       attr.setUsedAsTypeAttr();
       break;
-    case AttributeList::AT_AddressSpace:
+    case AttributeList::AT_address_space:
       HandleAddressSpaceTypeAttribute(type, attr, state.getSema());
       attr.setUsedAsTypeAttr();
       break;
@@ -4000,40 +4000,40 @@
         distributeObjCPointerTypeAttr(state, attr, type);
       attr.setUsedAsTypeAttr();
       break;
-    case AttributeList::AT_VectorSize:
+    case AttributeList::AT_vector_size:
       HandleVectorSizeAttr(type, attr, state.getSema());
       attr.setUsedAsTypeAttr();
       break;
-    case AttributeList::AT_ExtVectorType:
+    case AttributeList::AT_ext_vector_type:
       if (state.getDeclarator().getDeclSpec().getStorageClassSpec()
             != DeclSpec::SCS_typedef)
         HandleExtVectorTypeAttr(type, attr, state.getSema());
       attr.setUsedAsTypeAttr();
       break;
-    case AttributeList::AT_NeonVectorType:
+    case AttributeList::AT_neon_vector_type:
       HandleNeonVectorTypeAttr(type, attr, state.getSema(),
                                VectorType::NeonVector, "neon_vector_type");
       attr.setUsedAsTypeAttr();
       break;
-    case AttributeList::AT_NeonPolyVectorType:
+    case AttributeList::AT_neon_polyvector_type:
       HandleNeonVectorTypeAttr(type, attr, state.getSema(),
                                VectorType::NeonPolyVector,
                                "neon_polyvector_type");
       attr.setUsedAsTypeAttr();
       break;
-    case AttributeList::AT_OpenCLImageAccess:
+    case AttributeList::AT_opencl_image_access:
       HandleOpenCLImageAccessAttribute(type, attr, state.getSema());
       attr.setUsedAsTypeAttr();
       break;
 
-    case AttributeList::AT_Win64:
-    case AttributeList::AT_Ptr32:
-    case AttributeList::AT_Ptr64:
+    case AttributeList::AT_w64:
+    case AttributeList::AT_ptr32:
+    case AttributeList::AT_ptr64:
       // FIXME: don't ignore these
       attr.setUsedAsTypeAttr();
       break;
 
-    case AttributeList::AT_NSReturnsRetained:
+    case AttributeList::AT_ns_returns_retained:
       if (!state.getSema().getLangOpts().ObjCAutoRefCount)
 	break;
       // fallthrough into the function attrs
diff --git a/clang/lib/Sema/TargetAttributesSema.cpp b/clang/lib/Sema/TargetAttributesSema.cpp
index 25ace95..893c3e4 100644
--- a/clang/lib/Sema/TargetAttributesSema.cpp
+++ b/clang/lib/Sema/TargetAttributesSema.cpp
@@ -244,9 +244,9 @@
       if (Triple.getOS() == llvm::Triple::Win32 ||
           Triple.getOS() == llvm::Triple::MinGW32) {
         switch (Attr.getKind()) {
-        case AttributeList::AT_DLLImport: HandleDLLImportAttr(D, Attr, S);
+        case AttributeList::AT_dllimport: HandleDLLImportAttr(D, Attr, S);
                                           return true;
-        case AttributeList::AT_DLLExport: HandleDLLExportAttr(D, Attr, S);
+        case AttributeList::AT_dllexport: HandleDLLExportAttr(D, Attr, S);
                                           return true;
         default:                          break;
         }