<div dir="ltr"><div dir="auto">Yup, sorry for the delay. I submitted it overnight thinking it would be fixed this time. I have one more way that I think should fix it, but before trying it out, do you know any tips on how I can try to reproduce this locally? I see that you're running these on an x64 mac, but I can't seem to trigger this on our own mac builders. Also as a side question, do you what RA stands for in "<a href="http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/" title="<b><u>Build #60840 (Latest Build)</u></b>
<ul>
<li>Built @ <b>9:25 AM, 5/7/2019</b></li>
<li>Started 15 min ago</li>
<li>Lasted <b>13 min</b></li>
<li><b>Failed</b></li>
</ul>" style="box-sizing:border-box;color:rgb(92,53,102);font-family:Helvetica,Arial,sans-serif;font-size:14px">Clang Stage 1: cmake, incremental RA, using system compiler</a>"? It seems that I'm only breaking the non-incremental RA jobs, bit the incremental one still works fine with my change.</div><div dir="auto"><br></div><div>Thanks,</div><div>Leonard</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 7, 2019, 09:26 Jonas Devlieghere <<a href="mailto:jonas@devlieghere.com" target="_blank">jonas@devlieghere.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi Leonard,<div><div><br></div><div>It appears that your patch is still triggering an assertion on GreenDragon: <a href="http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/56255/consoleFull#312501878d489585b-5106-414a-ac11-3ff90657619c" rel="noreferrer" target="_blank">http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/56255/consoleFull#312501878d489585b-5106-414a-ac11-3ff90657619c</a></div><div><br></div><div>Can you please have a look?</div><div><br></div><div>Thanks,</div><div>Jonas</div></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 6, 2019 at 8:17 PM Leonard Chan via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" rel="noreferrer" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: leonardchan<br>
Date: Mon May  6 20:20:17 2019<br>
New Revision: 360109<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=360109&view=rev" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=360109&view=rev</a><br>
Log:<br>
Recommit r359859 "[Attribute/Diagnostics] Print macro if definition is an attribute declaration"<br>
<br>
Updated with fix for read of uninitialized memory.<br>
<br>
Added:<br>
    cfe/trunk/test/Frontend/macro_defined_type.cpp<br>
    cfe/trunk/test/Sema/address_space_print_macro.c<br>
Modified:<br>
    cfe/trunk/include/clang/AST/ASTContext.h<br>
    cfe/trunk/include/clang/AST/RecursiveASTVisitor.h<br>
    cfe/trunk/include/clang/AST/Type.h<br>
    cfe/trunk/include/clang/AST/TypeLoc.h<br>
    cfe/trunk/include/clang/AST/TypeNodes.def<br>
    cfe/trunk/include/clang/Parse/Parser.h<br>
    cfe/trunk/include/clang/Sema/ParsedAttr.h<br>
    cfe/trunk/include/clang/Sema/Sema.h<br>
    cfe/trunk/include/clang/Serialization/ASTBitCodes.h<br>
    cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp<br>
    cfe/trunk/lib/AST/ASTContext.cpp<br>
    cfe/trunk/lib/AST/ASTDiagnostic.cpp<br>
    cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp<br>
    cfe/trunk/lib/AST/ItaniumMangle.cpp<br>
    cfe/trunk/lib/AST/Type.cpp<br>
    cfe/trunk/lib/AST/TypePrinter.cpp<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
    cfe/trunk/lib/Parse/ParseDecl.cpp<br>
    cfe/trunk/lib/Sema/SemaExpr.cpp<br>
    cfe/trunk/lib/Sema/SemaStmt.cpp<br>
    cfe/trunk/lib/Sema/SemaType.cpp<br>
    cfe/trunk/lib/Sema/TreeTransform.h<br>
    cfe/trunk/lib/Serialization/ASTReader.cpp<br>
    cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
    cfe/trunk/test/Sema/address_spaces.c<br>
    cfe/trunk/test/SemaObjC/externally-retained.m<br>
    cfe/trunk/test/SemaObjC/gc-attributes.m<br>
    cfe/trunk/test/SemaObjC/mrc-weak.m<br>
    cfe/trunk/test/SemaObjCXX/<a href="http://gc-attributes.mm" rel="noreferrer noreferrer" target="_blank">gc-attributes.mm</a><br>
    cfe/trunk/tools/libclang/CIndex.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/ASTContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/ASTContext.h (original)<br>
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon May  6 20:20:17 2019<br>
@@ -1441,6 +1441,9 @@ public:<br>
<br>
   QualType getParenType(QualType NamedType) const;<br>
<br>
+  QualType getMacroQualifiedType(QualType UnderlyingTy,<br>
+                                 const IdentifierInfo *MacroII) const;<br>
+<br>
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,<br>
                              NestedNameSpecifier *NNS, QualType NamedType,<br>
                              TagDecl *OwnedTagDecl = nullptr) const;<br>
<br>
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)<br>
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon May  6 20:20:17 2019<br>
@@ -1065,6 +1065,9 @@ DEF_TRAVERSE_TYPE(AttributedType,<br>
<br>
 DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })<br>
<br>
+DEF_TRAVERSE_TYPE(MacroQualifiedType,<br>
+                  { TRY_TO(TraverseType(T->getUnderlyingType())); })<br>
+<br>
 DEF_TRAVERSE_TYPE(ElaboratedType, {<br>
   if (T->getQualifier()) {<br>
     TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));<br>
@@ -1308,6 +1311,9 @@ DEF_TRAVERSE_TYPELOC(InjectedClassNameTy<br>
<br>
 DEF_TRAVERSE_TYPELOC(ParenType, { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })<br>
<br>
+DEF_TRAVERSE_TYPELOC(MacroQualifiedType,<br>
+                     { TRY_TO(TraverseTypeLoc(TL.getInnerLoc())); })<br>
+<br>
 DEF_TRAVERSE_TYPELOC(AttributedType,<br>
                      { TRY_TO(TraverseTypeLoc(TL.getModifiedLoc())); })<br>
<br>
<br>
Modified: cfe/trunk/include/clang/AST/Type.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/Type.h (original)<br>
+++ cfe/trunk/include/clang/AST/Type.h Mon May  6 20:20:17 2019<br>
@@ -4184,6 +4184,41 @@ public:<br>
   static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }<br>
 };<br>
<br>
+/// Sugar type that represents a type that was qualified by a qualifier written<br>
+/// as a macro invocation.<br>
+class MacroQualifiedType : public Type {<br>
+  friend class ASTContext; // ASTContext creates these.<br>
+<br>
+  QualType UnderlyingTy;<br>
+  const IdentifierInfo *MacroII;<br>
+<br>
+  MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy,<br>
+                     const IdentifierInfo *MacroII)<br>
+      : Type(MacroQualified, CanonTy, UnderlyingTy->isDependentType(),<br>
+             UnderlyingTy->isInstantiationDependentType(),<br>
+             UnderlyingTy->isVariablyModifiedType(),<br>
+             UnderlyingTy->containsUnexpandedParameterPack()),<br>
+        UnderlyingTy(UnderlyingTy), MacroII(MacroII) {<br>
+    assert(isa<AttributedType>(UnderlyingTy) &&<br>
+           "Expected a macro qualified type to only wrap attributed types.");<br>
+  }<br>
+<br>
+public:<br>
+  const IdentifierInfo *getMacroIdentifier() const { return MacroII; }<br>
+  QualType getUnderlyingType() const { return UnderlyingTy; }<br>
+<br>
+  /// Return this attributed type's modified type with no qualifiers attached to<br>
+  /// it.<br>
+  QualType getModifiedType() const;<br>
+<br>
+  bool isSugared() const { return true; }<br>
+  QualType desugar() const;<br>
+<br>
+  static bool classof(const Type *T) {<br>
+    return T->getTypeClass() == MacroQualified;<br>
+  }<br>
+};<br>
+<br>
 /// Represents a `typeof` (or __typeof__) expression (a GCC extension).<br>
 class TypeOfExprType : public Type {<br>
   Expr *TOExpr;<br>
@@ -6805,6 +6840,8 @@ template <typename T> const T *Type::get<br>
       Ty = P->desugar().getTypePtr();<br>
     else if (const auto *A = dyn_cast<AdjustedType>(Ty))<br>
       Ty = A->desugar().getTypePtr();<br>
+    else if (const auto *M = dyn_cast<MacroQualifiedType>(Ty))<br>
+      Ty = M->desugar().getTypePtr();<br>
     else<br>
       break;<br>
   }<br>
<br>
Modified: cfe/trunk/include/clang/AST/TypeLoc.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)<br>
+++ cfe/trunk/include/clang/AST/TypeLoc.h Mon May  6 20:20:17 2019<br>
@@ -173,6 +173,9 @@ public:<br>
<br>
   TypeLoc IgnoreParens() const;<br>
<br>
+  /// Strips MacroDefinitionTypeLocs from a type location.<br>
+  TypeLoc IgnoreMacroDefinitions() const;<br>
+<br>
   /// Find a type with the location of an explicit type qualifier.<br>
   ///<br>
   /// The result, if non-null, will be one of:<br>
@@ -1080,6 +1083,39 @@ public:<br>
   }<br>
 };<br>
<br>
+struct MacroQualifiedLocInfo {<br>
+  SourceLocation ExpansionLoc;<br>
+};<br>
+<br>
+class MacroQualifiedTypeLoc<br>
+    : public ConcreteTypeLoc<UnqualTypeLoc, MacroQualifiedTypeLoc,<br>
+                             MacroQualifiedType, MacroQualifiedLocInfo> {<br>
+public:<br>
+  void initializeLocal(ASTContext &Context, SourceLocation Loc) {<br>
+    setExpansionLoc(Loc);<br>
+  }<br>
+<br>
+  TypeLoc getInnerLoc() const { return getInnerTypeLoc(); }<br>
+<br>
+  const IdentifierInfo *getMacroIdentifier() const {<br>
+    return getTypePtr()->getMacroIdentifier();<br>
+  }<br>
+<br>
+  SourceLocation getExpansionLoc() const {<br>
+    return this->getLocalData()->ExpansionLoc;<br>
+  }<br>
+<br>
+  void setExpansionLoc(SourceLocation Loc) {<br>
+    this->getLocalData()->ExpansionLoc = Loc;<br>
+  }<br>
+<br>
+  QualType getInnerType() const { return getTypePtr()->getUnderlyingType(); }<br>
+<br>
+  SourceRange getLocalSourceRange() const {<br>
+    return getInnerLoc().getLocalSourceRange();<br>
+  }<br>
+};<br>
+<br>
 struct ParenLocInfo {<br>
   SourceLocation LParenLoc;<br>
   SourceLocation RParenLoc;<br>
@@ -2289,6 +2325,8 @@ inline T TypeLoc::getAsAdjusted() const<br>
       Cur = ETL.getNamedTypeLoc();<br>
     else if (auto ATL = Cur.getAs<AdjustedTypeLoc>())<br>
       Cur = ATL.getOriginalLoc();<br>
+    else if (auto MQL = Cur.getAs<MacroQualifiedTypeLoc>())<br>
+      Cur = MQL.getInnerLoc();<br>
     else<br>
       break;<br>
   }<br>
<br>
Modified: cfe/trunk/include/clang/AST/TypeNodes.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeNodes.def?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeNodes.def?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/TypeNodes.def (original)<br>
+++ cfe/trunk/include/clang/AST/TypeNodes.def Mon May  6 20:20:17 2019<br>
@@ -82,6 +82,7 @@ TYPE(FunctionNoProto, FunctionType)<br>
 DEPENDENT_TYPE(UnresolvedUsing, Type)<br>
 NON_CANONICAL_TYPE(Paren, Type)<br>
 NON_CANONICAL_TYPE(Typedef, Type)<br>
+NON_CANONICAL_TYPE(MacroQualified, Type)<br>
 NON_CANONICAL_TYPE(Adjusted, Type)<br>
 NON_CANONICAL_TYPE(Decayed, AdjustedType)<br>
 NON_CANONICAL_UNLESS_DEPENDENT_TYPE(TypeOfExpr, Type)<br>
<br>
Modified: cfe/trunk/include/clang/Parse/Parser.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Parse/Parser.h (original)<br>
+++ cfe/trunk/include/clang/Parse/Parser.h Mon May  6 20:20:17 2019<br>
@@ -1158,6 +1158,7 @@ private:<br>
     Parser *Self;<br>
     CachedTokens Toks;<br>
     IdentifierInfo &AttrName;<br>
+    IdentifierInfo *MacroII = nullptr;<br>
     SourceLocation AttrNameLoc;<br>
     SmallVector<Decl*, 2> Decls;<br>
<br>
<br>
Modified: cfe/trunk/include/clang/Sema/ParsedAttr.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ParsedAttr.h?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ParsedAttr.h?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Sema/ParsedAttr.h (original)<br>
+++ cfe/trunk/include/clang/Sema/ParsedAttr.h Mon May  6 20:20:17 2019<br>
@@ -167,6 +167,8 @@ public:<br>
 private:<br>
   IdentifierInfo *AttrName;<br>
   IdentifierInfo *ScopeName;<br>
+  IdentifierInfo *MacroII = nullptr;<br>
+  SourceLocation MacroExpansionLoc;<br>
   SourceRange AttrRange;<br>
   SourceLocation ScopeLoc;<br>
   SourceLocation EllipsisLoc;<br>
@@ -547,6 +549,27 @@ public:<br>
     return getPropertyDataBuffer().SetterId;<br>
   }<br>
<br>
+  /// Set the macro identifier info object that this parsed attribute was<br>
+  /// declared in if it was declared in a macro. Also set the expansion location<br>
+  /// of the macro.<br>
+  void setMacroIdentifier(IdentifierInfo *MacroName, SourceLocation Loc) {<br>
+    MacroII = MacroName;<br>
+    MacroExpansionLoc = Loc;<br>
+  }<br>
+<br>
+  /// Returns true if this attribute was declared in a macro.<br>
+  bool hasMacroIdentifier() const { return MacroII != nullptr; }<br>
+<br>
+  /// Return the macro identifier if this attribute was declared in a macro.<br>
+  /// nullptr is returned if it was not declared in a macro.<br>
+  IdentifierInfo *getMacroIdentifier() const { return MacroII; }<br>
+<br>
+  SourceLocation getMacroExpansionLoc() const {<br>
+    assert(hasMacroIdentifier() && "Can only get the macro expansion location "<br>
+                                   "if this attribute has a macro identifier.");<br>
+    return MacroExpansionLoc;<br>
+  }<br>
+<br>
   /// Get an index into the attribute spelling list<br>
   /// defined in Attr.td. This index is used by an attribute<br>
   /// to pretty print itself.<br>
<br>
Modified: cfe/trunk/include/clang/Sema/Sema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Sema/Sema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/Sema.h Mon May  6 20:20:17 2019<br>
@@ -3506,7 +3506,7 @@ public:<br>
   // Check if there is an explicit attribute, but only look through parens.<br>
   // The intent is to look for an attribute on the current declarator, but not<br>
   // one that came from a typedef.<br>
-  bool hasExplicitCallingConv(QualType &T);<br>
+  bool hasExplicitCallingConv(QualType T);<br>
<br>
   /// Get the outermost AttributedType node that sets a calling convention.<br>
   /// Valid types should not have multiple attributes with different CCs.<br>
<br>
Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)<br>
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Mon May  6 20:20:17 2019<br>
@@ -1173,7 +1173,10 @@ namespace serialization {<br>
       TYPE_DEPENDENT_ADDRESS_SPACE = 47,<br>
<br>
       /// A dependentSizedVectorType record.<br>
-      TYPE_DEPENDENT_SIZED_VECTOR = 48<br>
+      TYPE_DEPENDENT_SIZED_VECTOR = 48,<br>
+<br>
+      /// A type defined in a macro.<br>
+      TYPE_MACRO_QUALIFIED = 49<br>
     };<br>
<br>
     /// The type IDs for special types constructed by semantic<br>
<br>
Modified: cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp (original)<br>
+++ cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp Mon May  6 20:20:17 2019<br>
@@ -68,6 +68,9 @@ public:<br>
         if (handleAttr(Attr, D))<br>
           break;<br>
         TL = Attr.getModifiedLoc();<br>
+      } else if (MacroQualifiedTypeLoc MDTL =<br>
+                     TL.getAs<MacroQualifiedTypeLoc>()) {<br>
+        TL = MDTL.getInnerLoc();<br>
       } else if (ArrayTypeLoc Arr = TL.getAs<ArrayTypeLoc>()) {<br>
         TL = Arr.getElementLoc();<br>
       } else if (PointerTypeLoc PT = TL.getAs<PointerTypeLoc>()) {<br>
<br>
Modified: cfe/trunk/lib/AST/ASTContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ASTContext.cpp (original)<br>
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon May  6 20:20:17 2019<br>
@@ -2047,6 +2047,10 @@ TypeInfo ASTContext::getTypeInfoImpl(con<br>
   case Type::Paren:<br>
     return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr());<br>
<br>
+  case Type::MacroQualified:<br>
+    return getTypeInfo(<br>
+        cast<MacroQualifiedType>(T)->getUnderlyingType().getTypePtr());<br>
+<br>
   case Type::ObjCTypeParam:<br>
     return getTypeInfo(cast<ObjCTypeParamType>(T)->desugar().getTypePtr());<br>
<br>
@@ -3929,7 +3933,7 @@ QualType ASTContext::getAttributedType(a<br>
<br>
   QualType canon = getCanonicalType(equivalentType);<br>
   type = new (*this, TypeAlignment)<br>
-           AttributedType(canon, attrKind, modifiedType, equivalentType);<br>
+      AttributedType(canon, attrKind, modifiedType, equivalentType);<br>
<br>
   Types.push_back(type);<br>
   AttributedTypes.InsertNode(type, insertPos);<br>
@@ -4210,6 +4214,19 @@ ASTContext::getParenType(QualType InnerT<br>
   return QualType(T, 0);<br>
 }<br>
<br>
+QualType<br>
+ASTContext::getMacroQualifiedType(QualType UnderlyingTy,<br>
+                                  const IdentifierInfo *MacroII) const {<br>
+  QualType Canon = UnderlyingTy;<br>
+  if (!Canon.isCanonical())<br>
+    Canon = getCanonicalType(UnderlyingTy);<br>
+<br>
+  auto *newType = new (*this, TypeAlignment)<br>
+      MacroQualifiedType(UnderlyingTy, Canon, MacroII);<br>
+  Types.push_back(newType);<br>
+  return QualType(newType, 0);<br>
+}<br>
+<br>
 QualType ASTContext::getDependentNameType(ElaboratedTypeKeyword Keyword,<br>
                                           NestedNameSpecifier *NNS,<br>
                                           const IdentifierInfo *Name,<br>
<br>
Modified: cfe/trunk/lib/AST/ASTDiagnostic.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDiagnostic.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDiagnostic.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ASTDiagnostic.cpp (original)<br>
+++ cfe/trunk/lib/AST/ASTDiagnostic.cpp Mon May  6 20:20:17 2019<br>
@@ -41,6 +41,11 @@ static QualType Desugar(ASTContext &Cont<br>
       QT = PT->desugar();<br>
       continue;<br>
     }<br>
+    // ... or a macro defined type ...<br>
+    if (const MacroQualifiedType *MDT = dyn_cast<MacroQualifiedType>(Ty)) {<br>
+      QT = MDT->desugar();<br>
+      continue;<br>
+    }<br>
     // ...or a substituted template type parameter ...<br>
     if (const SubstTemplateTypeParmType *ST =<br>
           dyn_cast<SubstTemplateTypeParmType>(Ty)) {<br>
<br>
Modified: cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp (original)<br>
+++ cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp Mon May  6 20:20:17 2019<br>
@@ -595,6 +595,13 @@ static bool IsStructurallyEquivalent(Str<br>
       return false;<br>
     break;<br>
<br>
+  case Type::MacroQualified:<br>
+    if (!IsStructurallyEquivalent(<br>
+            Context, cast<MacroQualifiedType>(T1)->getUnderlyingType(),<br>
+            cast<MacroQualifiedType>(T2)->getUnderlyingType()))<br>
+      return false;<br>
+    break;<br>
+<br>
   case Type::Typedef:<br>
     if (!IsStructurallyEquivalent(Context, cast<TypedefType>(T1)->getDecl(),<br>
                                   cast<TypedefType>(T2)->getDecl()))<br>
<br>
Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)<br>
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Mon May  6 20:20:17 2019<br>
@@ -1963,6 +1963,7 @@ bool CXXNameMangler::mangleUnresolvedTyp<br>
   case Type::ObjCTypeParam:<br>
   case Type::Atomic:<br>
   case Type::Pipe:<br>
+  case Type::MacroQualified:<br>
     llvm_unreachable("type is illegal as a nested name specifier");<br>
<br>
   case Type::SubstTemplateTypeParmPack:<br>
<br>
Modified: cfe/trunk/lib/AST/Type.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/Type.cpp (original)<br>
+++ cfe/trunk/lib/AST/Type.cpp Mon May  6 20:20:17 2019<br>
@@ -973,6 +973,7 @@ public:<br>
<br>
   SUGARED_TYPE_CLASS(Typedef)<br>
   SUGARED_TYPE_CLASS(ObjCTypeParam)<br>
+  SUGARED_TYPE_CLASS(MacroQualified)<br>
<br>
   QualType VisitAdjustedType(const AdjustedType *T) {<br>
     QualType originalType = recurse(T->getOriginalType());<br>
@@ -1735,6 +1736,10 @@ namespace {<br>
       return Visit(T->getModifiedType());<br>
     }<br>
<br>
+    Type *VisitMacroQualifiedType(const MacroQualifiedType *T) {<br>
+      return Visit(T->getUnderlyingType());<br>
+    }<br>
+<br>
     Type *VisitAdjustedType(const AdjustedType *T) {<br>
       return Visit(T->getOriginalType());<br>
     }<br>
@@ -3160,6 +3165,20 @@ QualType TypedefType::desugar() const {<br>
   return getDecl()->getUnderlyingType();<br>
 }<br>
<br>
+QualType MacroQualifiedType::desugar() const { return getUnderlyingType(); }<br>
+<br>
+QualType MacroQualifiedType::getModifiedType() const {<br>
+  // Step over MacroQualifiedTypes from the same macro to find the type<br>
+  // ultimately qualified by the macro qualifier.<br>
+  QualType Inner = cast<AttributedType>(getUnderlyingType())->getModifiedType();<br>
+  while (auto *InnerMQT = dyn_cast<MacroQualifiedType>(Inner)) {<br>
+    if (InnerMQT->getMacroIdentifier() != getMacroIdentifier())<br>
+      break;<br>
+    Inner = InnerMQT->getModifiedType();<br>
+  }<br>
+  return Inner;<br>
+}<br>
+<br>
 TypeOfExprType::TypeOfExprType(Expr *E, QualType can)<br>
     : Type(TypeOfExpr, can, E->isTypeDependent(),<br>
            E->isInstantiationDependent(),<br>
<br>
Modified: cfe/trunk/lib/AST/TypePrinter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)<br>
+++ cfe/trunk/lib/AST/TypePrinter.cpp Mon May  6 20:20:17 2019<br>
@@ -259,6 +259,7 @@ bool TypePrinter::canPrefixQualifiers(co<br>
     case Type::Paren:<br>
     case Type::PackExpansion:<br>
     case Type::SubstTemplateTypeParm:<br>
+    case Type::MacroQualified:<br>
       CanPrefixQualifiers = false;<br>
       break;<br>
<br>
@@ -963,6 +964,21 @@ void TypePrinter::printTypedefBefore(con<br>
   printTypeSpec(T->getDecl(), OS);<br>
 }<br>
<br>
+void TypePrinter::printMacroQualifiedBefore(const MacroQualifiedType *T,<br>
+                                            raw_ostream &OS) {<br>
+  StringRef MacroName = T->getMacroIdentifier()->getName();<br>
+  OS << MacroName << " ";<br>
+<br>
+  // Since this type is meant to print the macro instead of the whole attribute,<br>
+  // we trim any attributes and go directly to the original modified type.<br>
+  printBefore(T->getModifiedType(), OS);<br>
+}<br>
+<br>
+void TypePrinter::printMacroQualifiedAfter(const MacroQualifiedType *T,<br>
+                                           raw_ostream &OS) {<br>
+  printAfter(T->getModifiedType(), OS);<br>
+}<br>
+<br>
 void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) {}<br>
<br>
 void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T,<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon May  6 20:20:17 2019<br>
@@ -2844,6 +2844,9 @@ static QualType UnwrapTypeForDebugInfo(Q<br>
     case Type::Paren:<br>
       T = cast<ParenType>(T)->getInnerType();<br>
       break;<br>
+    case Type::MacroQualified:<br>
+      T = cast<MacroQualifiedType>(T)->getUnderlyingType();<br>
+      break;<br>
     case Type::SubstTemplateTypeParm:<br>
       T = cast<SubstTemplateTypeParmType>(T)->getReplacementType();<br>
       break;<br>
@@ -3023,6 +3026,7 @@ llvm::DIType *CGDebugInfo::CreateTypeNod<br>
   case Type::DeducedTemplateSpecialization:<br>
   case Type::Elaborated:<br>
   case Type::Paren:<br>
+  case Type::MacroQualified:<br>
   case Type::SubstTemplateTypeParm:<br>
   case Type::TypeOfExpr:<br>
   case Type::TypeOf:<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon May  6 20:20:17 2019<br>
@@ -2149,6 +2149,7 @@ void CodeGenFunction::EmitVariablyModifi<br>
     case Type::Attributed:<br>
     case Type::SubstTemplateTypeParm:<br>
     case Type::PackExpansion:<br>
+    case Type::MacroQualified:<br>
       // Keep walking after single level desugaring.<br>
       type = type.getSingleStepDesugaredType(getContext());<br>
       break;<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon May  6 20:20:17 2019<br>
@@ -85,6 +85,23 @@ static bool isAttributeLateParsed(const<br>
 #undef CLANG_ATTR_LATE_PARSED_LIST<br>
 }<br>
<br>
+/// Check if the a start and end source location expand to the same macro.<br>
+bool FindLocsWithCommonFileID(Preprocessor &PP, SourceLocation StartLoc,<br>
+                              SourceLocation EndLoc) {<br>
+  if (!StartLoc.isMacroID() || !EndLoc.isMacroID())<br>
+    return false;<br>
+<br>
+  SourceManager &SM = PP.getSourceManager();<br>
+  if (SM.getFileID(StartLoc) != SM.getFileID(EndLoc))<br>
+    return false;<br>
+<br>
+  bool AttrStartIsInMacro =<br>
+      Lexer::isAtStartOfMacroExpansion(StartLoc, SM, PP.getLangOpts());<br>
+  bool AttrEndIsInMacro =<br>
+      Lexer::isAtEndOfMacroExpansion(EndLoc, SM, PP.getLangOpts());<br>
+  return AttrStartIsInMacro && AttrEndIsInMacro;<br>
+}<br>
+<br>
 /// ParseGNUAttributes - Parse a non-empty attributes list.<br>
 ///<br>
 /// [GNU] attributes:<br>
@@ -133,7 +150,10 @@ void Parser::ParseGNUAttributes(ParsedAt<br>
   assert(Tok.is(tok::kw___attribute) && "Not a GNU attribute list!");<br>
<br>
   while (Tok.is(tok::kw___attribute)) {<br>
-    ConsumeToken();<br>
+    SourceLocation AttrTokLoc = ConsumeToken();<br>
+    unsigned OldNumAttrs = attrs.size();<br>
+    unsigned OldNumLateAttrs = LateAttrs ? LateAttrs->size() : 0;<br>
+<br>
     if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,<br>
                          "attribute")) {<br>
       SkipUntil(tok::r_paren, StopAtSemi); // skip until ) or ;<br>
@@ -201,6 +221,24 @@ void Parser::ParseGNUAttributes(ParsedAt<br>
       SkipUntil(tok::r_paren, StopAtSemi);<br>
     if (endLoc)<br>
       *endLoc = Loc;<br>
+<br>
+    // If this was declared in a macro, attach the macro IdentifierInfo to the<br>
+    // parsed attribute.<br>
+    if (FindLocsWithCommonFileID(PP, AttrTokLoc, Loc)) {<br>
+      auto &SM = PP.getSourceManager();<br>
+      CharSourceRange ExpansionRange = SM.getExpansionRange(AttrTokLoc);<br>
+      StringRef FoundName =<br>
+          Lexer::getSourceText(ExpansionRange, SM, PP.getLangOpts());<br>
+      IdentifierInfo *MacroII = PP.getIdentifierInfo(FoundName);<br>
+<br>
+      for (unsigned i = OldNumAttrs; i < attrs.size(); ++i)<br>
+        attrs[i].setMacroIdentifier(MacroII, ExpansionRange.getBegin());<br>
+<br>
+      if (LateAttrs) {<br>
+        for (unsigned i = OldNumLateAttrs; i < LateAttrs->size(); ++i)<br>
+          (*LateAttrs)[i]->MacroII = MacroII;<br>
+      }<br>
+    }<br>
   }<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon May  6 20:20:17 2019<br>
@@ -4096,6 +4096,7 @@ static void captureVariablyModifiedType(<br>
     case Type::Attributed:<br>
     case Type::SubstTemplateTypeParm:<br>
     case Type::PackExpansion:<br>
+    case Type::MacroQualified:<br>
       // Keep walking after single level desugaring.<br>
       T = T.getSingleStepDesugaredType(Context);<br>
       break;<br>
@@ -13695,8 +13696,8 @@ void Sema::ActOnBlockArguments(SourceLoc<br>
   // Look for an explicit signature in that function type.<br>
   FunctionProtoTypeLoc ExplicitSignature;<br>
<br>
-  if ((ExplicitSignature =<br>
-           Sig->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>())) {<br>
+  if ((ExplicitSignature = Sig->getTypeLoc()<br>
+                               .getAsAdjusted<FunctionProtoTypeLoc>())) {<br>
<br>
     // Check whether that explicit signature was synthesized by<br>
     // GetTypeForDeclarator.  If so, don't save that as part of the<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon May  6 20:20:17 2019<br>
@@ -3390,10 +3390,10 @@ bool LocalTypedefNameReferencer::VisitRe<br>
 }<br>
<br>
 TypeLoc Sema::getReturnTypeLoc(FunctionDecl *FD) const {<br>
-  TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc().IgnoreParens();<br>
-  while (auto ATL = TL.getAs<AttributedTypeLoc>())<br>
-    TL = ATL.getModifiedLoc().IgnoreParens();<br>
-  return TL.castAs<FunctionProtoTypeLoc>().getReturnLoc();<br>
+  return FD->getTypeSourceInfo()<br>
+      ->getTypeLoc()<br>
+      .getAsAdjusted<FunctionProtoTypeLoc>()<br>
+      .getReturnLoc();<br>
 }<br>
<br>
 /// Deduce the return type for a function from a returned expression, per<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaType.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon May  6 20:20:17 2019<br>
@@ -182,6 +182,10 @@ namespace {<br>
     SmallVector<TypeAttrPair, 8> AttrsForTypes;<br>
     bool AttrsForTypesSorted = true;<br>
<br>
+    /// MacroQualifiedTypes mapping to macro expansion locations that will be<br>
+    /// stored in a MacroQualifiedTypeLoc.<br>
+    llvm::DenseMap<const MacroQualifiedType *, SourceLocation> LocsForMacros;<br>
+<br>
     /// Flag to indicate we parsed a noderef attribute. This is used for<br>
     /// validating that noderef was used on a pointer or array.<br>
     bool parsedNoDeref;<br>
@@ -295,6 +299,19 @@ namespace {<br>
       llvm_unreachable("no Attr* for AttributedType*");<br>
     }<br>
<br>
+    SourceLocation<br>
+    getExpansionLocForMacroQualifiedType(const MacroQualifiedType *MQT) const {<br>
+      auto FoundLoc = LocsForMacros.find(MQT);<br>
+      assert(FoundLoc != LocsForMacros.end() &&<br>
+             "Unable to find macro expansion location for MacroQualifedType");<br>
+      return FoundLoc->second;<br>
+    }<br>
+<br>
+    void setExpansionLocForMacroQualifiedType(const MacroQualifiedType *MQT,<br>
+                                              SourceLocation Loc) {<br>
+      LocsForMacros[MQT] = Loc;<br>
+    }<br>
+<br>
     void setParsedNoDeref(bool parsed) { parsedNoDeref = parsed; }<br>
<br>
     bool didParseNoDeref() const { return parsedNoDeref; }<br>
@@ -5644,6 +5661,9 @@ namespace {<br>
       assert(Chunk.Kind == DeclaratorChunk::Pipe);<br>
       TL.setKWLoc(Chunk.Loc);<br>
     }<br>
+    void VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {<br>
+      TL.setExpansionLoc(Chunk.Loc);<br>
+    }<br>
<br>
     void VisitTypeLoc(TypeLoc TL) {<br>
       llvm_unreachable("unsupported TypeLoc kind in declarator!");<br>
@@ -5722,6 +5742,12 @@ GetTypeSourceInfoForDeclarator(TypeProce<br>
       CurrTL = ATL.getValueLoc().getUnqualifiedLoc();<br>
     }<br>
<br>
+    while (MacroQualifiedTypeLoc TL = CurrTL.getAs<MacroQualifiedTypeLoc>()) {<br>
+      TL.setExpansionLoc(<br>
+          State.getExpansionLocForMacroQualifiedType(TL.getTypePtr()));<br>
+      CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();<br>
+    }<br>
+<br>
     while (AttributedTypeLoc TL = CurrTL.getAs<AttributedTypeLoc>()) {<br>
       fillAttributedTypeLoc(TL, State);<br>
       CurrTL = TL.getNextTypeLoc().getUnqualifiedLoc();<br>
@@ -6982,12 +7008,16 @@ static bool handleFunctionTypeAttr(TypeP<br>
   return true;<br>
 }<br>
<br>
-bool Sema::hasExplicitCallingConv(QualType &T) {<br>
-  QualType R = T.IgnoreParens();<br>
-  while (const AttributedType *AT = dyn_cast<AttributedType>(R)) {<br>
+bool Sema::hasExplicitCallingConv(QualType T) {<br>
+  const AttributedType *AT;<br>
+<br>
+  // Stop if we'd be stripping off a typedef sugar node to reach the<br>
+  // AttributedType.<br>
+  while ((AT = T->getAs<AttributedType>()) &&<br>
+         AT->getAs<TypedefType>() == T->getAs<TypedefType>()) {<br>
     if (AT->isCallingConv())<br>
       return true;<br>
-    R = AT->getModifiedType().IgnoreParens();<br>
+    T = AT->getModifiedType();<br>
   }<br>
   return false;<br>
 }<br>
@@ -7572,6 +7602,18 @@ static void processTypeAttrs(TypeProcess<br>
         distributeFunctionTypeAttr(state, attr, type);<br>
       break;<br>
     }<br>
+<br>
+    // Handle attributes that are defined in a macro. We do not want this to be<br>
+    // applied to ObjC builtin attributes.<br>
+    if (isa<AttributedType>(type) && attr.hasMacroIdentifier() &&<br>
+        !type.getQualifiers().hasObjCLifetime() &&<br>
+        !type.getQualifiers().hasObjCGCAttr()) {<br>
+      const IdentifierInfo *MacroII = attr.getMacroIdentifier();<br>
+      type = state.getSema().Context.getMacroQualifiedType(type, MacroII);<br>
+      state.setExpansionLocForMacroQualifiedType(<br>
+          cast<MacroQualifiedType>(type.getTypePtr()),<br>
+          attr.getMacroExpansionLoc());<br>
+    }<br>
   }<br>
<br>
   if (!state.getSema().getLangOpts().OpenCL ||<br>
<br>
Modified: cfe/trunk/lib/Sema/TreeTransform.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/TreeTransform.h (original)<br>
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon May  6 20:20:17 2019<br>
@@ -883,6 +883,12 @@ public:<br>
     return SemaRef.Context.getTypeDeclType(Typedef);<br>
   }<br>
<br>
+  /// Build a new MacroDefined type.<br>
+  QualType RebuildMacroQualifiedType(QualType T,<br>
+                                     const IdentifierInfo *MacroII) {<br>
+    return SemaRef.Context.getMacroQualifiedType(T, MacroII);<br>
+  }<br>
+<br>
   /// Build a new class/struct/union type.<br>
   QualType RebuildRecordType(RecordDecl *Record) {<br>
     return SemaRef.Context.getTypeDeclType(Record);<br>
@@ -6193,6 +6199,27 @@ TreeTransform<Derived>::TransformParenTy<br>
   return Result;<br>
 }<br>
<br>
+template <typename Derived><br>
+QualType<br>
+TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,<br>
+                                                    MacroQualifiedTypeLoc TL) {<br>
+  QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());<br>
+  if (Inner.isNull())<br>
+    return QualType();<br>
+<br>
+  QualType Result = TL.getType();<br>
+  if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {<br>
+    Result =<br>
+        getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());<br>
+    if (Result.isNull())<br>
+      return QualType();<br>
+  }<br>
+<br>
+  MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);<br>
+  NewTL.setExpansionLoc(TL.getExpansionLoc());<br>
+  return Result;<br>
+}<br>
+<br>
 template<typename Derived><br>
 QualType TreeTransform<Derived>::TransformDependentNameType(<br>
     TypeLocBuilder &TLB, DependentNameTypeLoc TL) {<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon May  6 20:20:17 2019<br>
@@ -6200,6 +6200,16 @@ QualType ASTReader::readTypeRecord(unsig<br>
     return Context.getParenType(InnerType);<br>
   }<br>
<br>
+  case TYPE_MACRO_QUALIFIED: {<br>
+    if (Record.size() != 2) {<br>
+      Error("incorrect encoding of macro defined type");<br>
+      return QualType();<br>
+    }<br>
+    QualType UnderlyingTy = readType(*Loc.F, Record, Idx);<br>
+    IdentifierInfo *MacroII = GetIdentifierInfo(*Loc.F, Record, Idx);<br>
+    return Context.getMacroQualifiedType(UnderlyingTy, MacroII);<br>
+  }<br>
+<br>
   case TYPE_PACK_EXPANSION: {<br>
     if (Record.size() != 2) {<br>
       Error("incorrect encoding of pack expansion type");<br>
@@ -6521,6 +6531,10 @@ void TypeLocReader::VisitAdjustedTypeLoc<br>
   // nothing to do<br>
 }<br>
<br>
+void TypeLocReader::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {<br>
+  TL.setExpansionLoc(ReadSourceLocation());<br>
+}<br>
+<br>
 void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {<br>
   TL.setCaretLoc(ReadSourceLocation());<br>
 }<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon May  6 20:20:17 2019<br>
@@ -516,6 +516,12 @@ void ASTTypeWriter::VisitParenType(const<br>
   Code = TYPE_PAREN;<br>
 }<br>
<br>
+void ASTTypeWriter::VisitMacroQualifiedType(const MacroQualifiedType *T) {<br>
+  Record.AddTypeRef(T->getUnderlyingType());<br>
+  Record.AddIdentifierRef(T->getMacroIdentifier());<br>
+  Code = TYPE_MACRO_QUALIFIED;<br>
+}<br>
+<br>
 void ASTTypeWriter::VisitElaboratedType(const ElaboratedType *T) {<br>
   Record.push_back(T->getKeyword());<br>
   Record.AddNestedNameSpecifier(T->getQualifier());<br>
@@ -802,6 +808,10 @@ void TypeLocWriter::VisitParenTypeLoc(Pa<br>
   Record.AddSourceLocation(TL.getRParenLoc());<br>
 }<br>
<br>
+void TypeLocWriter::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {<br>
+  Record.AddSourceLocation(TL.getExpansionLoc());<br>
+}<br>
+<br>
 void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {<br>
   Record.AddSourceLocation(TL.getElaboratedKeywordLoc());<br>
   Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc());<br>
@@ -1219,6 +1229,7 @@ void ASTWriter::WriteBlockInfoBlock() {<br>
   RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION);<br>
   RECORD(TYPE_DEPENDENT_SIZED_ARRAY);<br>
   RECORD(TYPE_PAREN);<br>
+  RECORD(TYPE_MACRO_QUALIFIED);<br>
   RECORD(TYPE_PACK_EXPANSION);<br>
   RECORD(TYPE_ATTRIBUTED);<br>
   RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK);<br>
<br>
Added: cfe/trunk/test/Frontend/macro_defined_type.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/macro_defined_type.cpp?rev=360109&view=auto" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/macro_defined_type.cpp?rev=360109&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Frontend/macro_defined_type.cpp (added)<br>
+++ cfe/trunk/test/Frontend/macro_defined_type.cpp Mon May  6 20:20:17 2019<br>
@@ -0,0 +1,15 @@<br>
+// RUN: %clang_cc1 -fsyntax-only -verify %s<br>
+<br>
+#define NODEREF __attribute__((noderef))<br>
+<br>
+void Func() {<br>
+  int NODEREF i; // expected-warning{{'noderef' can only be used on an array or pointer type}}<br>
+  int NODEREF *i_ptr;<br>
+<br>
+  // There should be no difference whether a macro defined type is used or not.<br>
+  auto __attribute__((noderef)) *auto_i_ptr = i_ptr;<br>
+  auto __attribute__((noderef)) auto_i = i; // expected-warning{{'noderef' can only be used on an array or pointer type}}<br>
+<br>
+  auto NODEREF *auto_i_ptr2 = i_ptr;<br>
+  auto NODEREF auto_i2 = i; // expected-warning{{'noderef' can only be used on an array or pointer type}}<br>
+}<br>
<br>
Added: cfe/trunk/test/Sema/address_space_print_macro.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_space_print_macro.c?rev=360109&view=auto" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_space_print_macro.c?rev=360109&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/address_space_print_macro.c (added)<br>
+++ cfe/trunk/test/Sema/address_space_print_macro.c Mon May  6 20:20:17 2019<br>
@@ -0,0 +1,67 @@<br>
+// RUN: %clang_cc1 %s -fsyntax-only -verify<br>
+<br>
+#define AS1 __attribute__((address_space(1)))<br>
+#define AS2 __attribute__((address_space(2), annotate("foo")))<br>
+#define AS_ND __attribute__((address_space(2), noderef))<br>
+<br>
+#define AS(i) address_space(i)<br>
+#define AS3 __attribute__((AS(3)))<br>
+#define AS5 __attribute__((address_space(5))) char<br>
+<br>
+void normal_case() {<br>
+  int *p = 0;<br>
+  __attribute__((address_space(1))) int *q = p; // expected-error{{initializing '__attribute__((address_space(1))) int *' with an expression of type 'int *' changes address space of pointer}}<br>
+}<br>
+<br>
+char *cmp(AS1 char *x, AS2 char *y) {<br>
+  return x < y ? x : y; // expected-error{{conditional operator with the second and third operands of type  ('AS1 char *' and 'AS2 char *') which are pointers to non-overlapping address spaces}}<br>
+}<br>
+<br>
+__attribute__((address_space(1))) char test_array[10];<br>
+void test3(void) {<br>
+  extern void test3_helper(char *p); // expected-note{{passing argument to parameter 'p' here}}<br>
+  test3_helper(test_array);          // expected-error{{passing '__attribute__((address_space(1))) char *' to parameter of type 'char *' changes address space of pointer}}<br>
+}<br>
+<br>
+char AS2 *test4_array;<br>
+void test4(void) {<br>
+  extern void test3_helper(char *p); // expected-note{{passing argument to parameter 'p' here}}<br>
+  test3_helper(test4_array);         // expected-error{{passing 'AS2 char *' to parameter of type 'char *' changes address space of pointer}}<br>
+}<br>
+<br>
+void func() {<br>
+  char AS1 *x;<br>
+  char AS3 *x2;<br>
+  AS5 *x3;<br>
+  char *y;<br>
+  y = x;  // expected-error{{assigning 'AS1 char *' to 'char *' changes address space of pointer}}<br>
+  y = x2; // expected-error{{assigning 'AS3 char *' to 'char *' changes address space of pointer}}<br>
+  y = x3; // expected-error{{assigning '__attribute__((address_space(5))) char *' to 'char *' changes address space of pointer}}<br>
+}<br>
+<br>
+void multiple_attrs(AS_ND int *x) {<br>
+  __attribute__((address_space(2))) int *y = x; // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}}<br>
+}<br>
+<br>
+void override_macro_name() {<br>
+#define ATTRS __attribute__((noderef)) // expected-note{{previous definition is here}}<br>
+  ATTRS<br>
+#define ATTRS __attribute__((address_space(1))) // expected-warning{{'ATTRS' macro redefined}}<br>
+  ATTRS<br>
+  int *x;<br>
+<br>
+  int AS_ND *y = x; // expected-error{{initializing 'AS_ND int *' with an expression of type 'ATTRS int *' changes address space of pointer}}<br>
+}<br>
+<br>
+void partial_macro_declaration() {<br>
+#define ATTRS2 __attribute__((noderef))<br>
+  ATTRS2 __attribute__((address_space(1))) int *x;<br>
+<br>
+  int AS_ND *y = x; // expected-error{{initializing 'AS_ND int *' with an expression of type 'ATTRS2 int __attribute__((address_space(1))) *' changes address space of pointer}}<br>
+<br>
+  // The attribute not wrapped with a macro should be printed regularly.<br>
+#define ATTRS3 __attribute__((address_space(1)))<br>
+  ATTRS3 __attribute__((noderef)) int *x2;<br>
+<br>
+  int AS_ND *y2 = x2; // expected-error{{initializing 'AS_ND int *' with an expression of type 'ATTRS3 int * __attribute__((noderef))' changes address space of pointer}}<br>
+}<br>
<br>
Modified: cfe/trunk/test/Sema/address_spaces.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_spaces.c?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_spaces.c?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/address_spaces.c (original)<br>
+++ cfe/trunk/test/Sema/address_spaces.c Mon May  6 20:20:17 2019<br>
@@ -71,7 +71,7 @@ __attribute__((address_space("12"))) int<br>
<br>
 // Clang extension doesn't forbid operations on pointers to different address spaces.<br>
 char* cmp(_AS1 char *x,  _AS2 char *y) {<br>
-  return x < y ? x : y; // expected-error{{conditional operator with the second and third operands of type  ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *') which are pointers to non-overlapping address spaces}}<br>
+  return x < y ? x : y; // expected-error{{conditional operator with the second and third operands of type  ('_AS1 char *' and '_AS2 char *') which are pointers to non-overlapping address spaces}}<br>
 }<br>
<br>
 struct SomeStruct {<br>
<br>
Modified: cfe/trunk/test/SemaObjC/externally-retained.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/externally-retained.m?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/externally-retained.m?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaObjC/externally-retained.m (original)<br>
+++ cfe/trunk/test/SemaObjC/externally-retained.m Mon May  6 20:20:17 2019<br>
@@ -68,6 +68,12 @@ void (^blk)(ObjCTy *, ObjCTy *) =<br>
   second = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}<br>
 };<br>
<br>
+void (^blk2)(ObjCTy *, ObjCTy *) =<br>
+    ^(__strong ObjCTy *first, ObjCTy *second) __attribute__((objc_externally_retained)) {<br>
+  first = 0;<br>
+  second = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}<br>
+};<br>
+<br>
 void test8(EXT_RET ObjCTy *x) {} // expected-warning{{'objc_externally_retained' attribute only applies to variables}}<br>
<br>
 #pragma clang attribute ext_ret.push(__attribute__((objc_externally_retained)), apply_to=any(function, block, objc_method))<br>
<br>
Modified: cfe/trunk/test/SemaObjC/gc-attributes.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/gc-attributes.m?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/gc-attributes.m?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaObjC/gc-attributes.m (original)<br>
+++ cfe/trunk/test/SemaObjC/gc-attributes.m Mon May  6 20:20:17 2019<br>
@@ -9,7 +9,7 @@ void test_f0() {<br>
   A *a;<br>
   static __weak A *a2;<br>
   f0(&a);<br>
-  f0(&a2); // expected-warning{{passing 'A *__weak *' to parameter of type 'A *__strong *' discards qualifiers}} <br>
+  f0(&a2); // expected-warning{{passing 'A *__weak *' to parameter of type 'A *__strong *' discards qualifiers}}<br>
 }<br>
<br>
 void f1(__weak A**); // expected-note{{passing argument to parameter here}}<br>
@@ -18,7 +18,7 @@ void test_f1() {<br>
   A *a;<br>
   __strong A *a2;<br>
   f1(&a);<br>
-  f1(&a2); // expected-warning{{passing 'A *__strong *' to parameter of type 'A *__weak *' discards qualifiers}} <br>
+  f1(&a2); // expected-warning{{passing 'A *__strong *' to parameter of type 'A *__weak *' discards qualifiers}}<br>
 }<br>
<br>
 // These qualifiers should silently expand to nothing in GC mode.<br>
<br>
Modified: cfe/trunk/test/SemaObjC/mrc-weak.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/mrc-weak.m?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/mrc-weak.m?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaObjC/mrc-weak.m (original)<br>
+++ cfe/trunk/test/SemaObjC/mrc-weak.m Mon May  6 20:20:17 2019<br>
@@ -62,6 +62,6 @@ void test_unsafe_unretained_cast(id *val<br>
<br>
 void test_cast_qualifier_inference(__weak id *value) {<br>
   __weak id *a = (id*) value;<br>
-  __unsafe_unretained id *b = (id*) value; // expected-error {{initializing 'id *' with an expression of type '__weak id *' changes retain/release properties of pointer}}<br>
+  __unsafe_unretained id *b = (id *)value; // expected-error {{initializing '__unsafe_unretained id *' with an expression of type '__weak id *' changes retain/release properties of pointer}}<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/test/SemaObjCXX/<a href="http://gc-attributes.mm" rel="noreferrer noreferrer" target="_blank">gc-attributes.mm</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/gc-attributes.mm?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/gc-attributes.mm?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaObjCXX/<a href="http://gc-attributes.mm" rel="noreferrer noreferrer" target="_blank">gc-attributes.mm</a> (original)<br>
+++ cfe/trunk/test/SemaObjCXX/<a href="http://gc-attributes.mm" rel="noreferrer noreferrer" target="_blank">gc-attributes.mm</a> Mon May  6 20:20:17 2019<br>
@@ -3,7 +3,7 @@<br>
 @interface A<br>
 @end<br>
<br>
-void f0(__strong A**); // expected-note{{candidate function not viable: 1st argument ('A *__weak *') has __weak ownership, but parameter has __strong ownership}}<br>
+void f0(__strong A **); // expected-note{{candidate function not viable: 1st argument ('A *__weak *') has __weak ownership, but parameter has __strong ownership}}<br>
<br>
 void test_f0() {<br>
   A *a;<br>
@@ -12,7 +12,7 @@ void test_f0() {<br>
   f0(&a2); // expected-error{{no matching function}}<br>
 }<br>
<br>
-void f1(__weak A**); // expected-note{{candidate function not viable: 1st argument ('A *__strong *') has __strong ownership, but parameter has __weak ownership}}<br>
+void f1(__weak A **); // expected-note{{candidate function not viable: 1st argument ('A *__strong *') has __strong ownership, but parameter has __weak ownership}}<br>
<br>
 void test_f1() {<br>
   A *a;<br>
<br>
Modified: cfe/trunk/tools/libclang/CIndex.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=360109&r1=360108&r2=360109&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=360109&r1=360108&r2=360109&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/libclang/CIndex.cpp (original)<br>
+++ cfe/trunk/tools/libclang/CIndex.cpp Mon May  6 20:20:17 2019<br>
@@ -1614,6 +1614,10 @@ bool CursorVisitor::VisitParenTypeLoc(Pa<br>
   return Visit(TL.getInnerLoc());<br>
 }<br>
<br>
+bool CursorVisitor::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {<br>
+  return Visit(TL.getInnerLoc());<br>
+}<br>
+<br>
 bool CursorVisitor::VisitPointerTypeLoc(PointerTypeLoc TL) {<br>
   return Visit(TL.getPointeeLoc());<br>
 }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" rel="noreferrer" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</blockquote></div>