From: Richard Smith Date: Thu, 9 Aug 2018 01:21:06 +0000 (+0000) Subject: Refactor attribute printing to be a bit more obviously-correct. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6a0f14e93911365117e48208446afebde224ad9;p=clang Refactor attribute printing to be a bit more obviously-correct. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339306 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index 1acb4ca668..1cb5ff46b5 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -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 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 index 0000000000..223e27b397 --- /dev/null +++ b/test/Misc/ast-print-attr.c @@ -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]];