]> granicus.if.org Git - clang/commitdiff
Refactor attribute printing to be a bit more obviously-correct.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 9 Aug 2018 01:21:06 +0000 (01:21 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 9 Aug 2018 01:21:06 +0000 (01:21 +0000)
No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339306 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/TypePrinter.cpp
test/Misc/ast-print-attr.c [new file with mode: 0644]

index 1acb4ca6683c59d0a2e97d3b18eb41e8a9c82977..1cb5ff46b5553d307187ef6aee5bd3cd035407d6 100644 (file)
@@ -1398,25 +1398,21 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
       T->getAttrKind() == AttributedType::attr_objc_ownership)
     return printAfter(T->getEquivalentType(), OS);
 
-  if (T->getAttrKind() == AttributedType::attr_objc_kindof)
-    return;
-
-  // TODO: not all attributes are GCC-style attributes.
-  if (T->isMSTypeSpec())
-    return;
-
-  // Nothing to print after.
-  if (T->getAttrKind() == AttributedType::attr_nonnull ||
-      T->getAttrKind() == AttributedType::attr_nullable ||
-      T->getAttrKind() == AttributedType::attr_null_unspecified)
-    return printAfter(T->getModifiedType(), OS);
-
   // If this is a calling convention attribute, don't print the implicit CC from
   // the modified type.
   SaveAndRestore<bool> MaybeSuppressCC(InsideCCAttribute, T->isCallingConv());
 
   printAfter(T->getModifiedType(), OS);
 
+  // Some attributes are printed as qualifiers before the type, so we have
+  // nothing left to do.
+  if (T->getAttrKind() == AttributedType::attr_objc_kindof ||
+      T->isMSTypeSpec() ||
+      T->getAttrKind() == AttributedType::attr_nonnull ||
+      T->getAttrKind() == AttributedType::attr_nullable ||
+      T->getAttrKind() == AttributedType::attr_null_unspecified)
+    return;
+
   // Don't print the inert __unsafe_unretained attribute at all.
   if (T->getAttrKind() == AttributedType::attr_objc_inert_unsafe_unretained)
     return;
diff --git a/test/Misc/ast-print-attr.c b/test/Misc/ast-print-attr.c
new file mode 100644 (file)
index 0000000..223e27b
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -ast-print -x objective-c++ -fms-extensions %s -o - | FileCheck %s
+
+// CHECK: using A = __kindof id (*)[1];
+using A = __kindof id (*)[1];
+
+// CHECK: using B = int ** __ptr32 *[3];
+using B = int ** __ptr32 *[3];
+
+// FIXME: This is the wrong spelling for the attribute.
+// FIXME: Too many parens here!
+// CHECK: using C = int ((*))() __attribute__((cdecl));
+using C = int (*)() [[gnu::cdecl]];