[PATCH] D51229: [Sema/Attribute] Make types declared with address_space an AttributedType

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 24 15:17:08 PDT 2018


leonardchan updated this revision to Diff 162487.
leonardchan marked 3 inline comments as done.

Repository:
  rC Clang

https://reviews.llvm.org/D51229

Files:
  include/clang/Basic/Attr.td
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaType.cpp


Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -5767,7 +5767,10 @@
 /// specified type.  The attribute contains 1 argument, the id of the address
 /// space for the type.
 static void HandleAddressSpaceTypeAttribute(QualType &Type,
-                                            const ParsedAttr &Attr, Sema &S) {
+                                            const ParsedAttr &Attr,
+                                            TypeProcessingState &State) {
+  Sema &S = State.getSema();
+
   // ISO/IEC TR 18037 S5.3 (amending C99 6.7.3): "A function type shall not be
   // qualified by an address-space qualifier."
   if (Type->isFunctionType()) {
@@ -5809,10 +5812,18 @@
     // the type.
     QualType T = S.BuildAddressSpaceAttr(Type, ASArgExpr, Attr.getLoc());
 
-    if (!T.isNull())
+    if (!T.isNull()) {
+      if (!T->getAs<DependentAddressSpaceType>()) {
+        ASTContext &Ctx = S.Context;
+        auto *ASAttr = ::new (Ctx) AddressSpaceAttr(
+            Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex(),
+            static_cast<unsigned>(T.getQualifiers().getAddressSpace()));
+        T = State.getAttributedType(ASAttr, T, T);
+      }
       Type = T;
-    else
+    } else {
       Attr.setInvalid();
+    }
   } else {
     // The keyword-based type attributes imply which address space to use.
     switch (Attr.getKind()) {
@@ -7282,7 +7293,7 @@
     case ParsedAttr::AT_OpenCLConstantAddressSpace:
     case ParsedAttr::AT_OpenCLGenericAddressSpace:
     case ParsedAttr::AT_AddressSpace:
-      HandleAddressSpaceTypeAttribute(type, attr, state.getSema());
+      HandleAddressSpaceTypeAttribute(type, attr, state);
       attr.setUsedAsTypeAttr();
       break;
     OBJC_POINTER_TYPE_ATTRS_CASELIST:
Index: lib/AST/TypePrinter.cpp
===================================================================
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -1427,6 +1427,12 @@
     return;
   }
 
+  // The printing of the address_space attribute is handled by the qualifier
+  // since it is still stored in the qualifier. Return early to prevent printing
+  // this twice.
+  if (T->getAttrKind() == attr::AddressSpace)
+    return;
+
   OS << " __attribute__((";
   switch (T->getAttrKind()) {
 #define TYPE_ATTR(NAME)
@@ -1456,6 +1462,7 @@
   case attr::Ptr64:
   case attr::SPtr:
   case attr::UPtr:
+  case attr::AddressSpace:
     llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:
Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -564,8 +564,6 @@
   let Spellings = [Clang<"address_space">];
   let Args = [IntArgument<"AddressSpace">];
   let Documentation = [Undocumented];
-  // Represented as a qualifier or DependentAddressSpaceType instead.
-  let ASTNode = 0;
 }
 
 def Alias : Attr {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51229.162487.patch
Type: text/x-patch
Size: 3020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180824/c1507273/attachment.bin>


More information about the cfe-commits mailing list