Index: include/clang-c/Index.h =================================================================== --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -1337,7 +1337,12 @@ /** * Used to indicate that attributed types should be included in CXType. */ - CXTranslationUnit_IncludeAttributedTypes = 0x1000 + CXTranslationUnit_IncludeAttributedTypes = 0x1000, + + /** + * Used to indicate that implicit attributes should be visited. + */ + CXTranslationUnit_VisitImplicitAttributes = 0x2000 }; /** Index: test/Index/implicit-attrs.m =================================================================== --- /dev/null +++ test/Index/implicit-attrs.m @@ -0,0 +1,6 @@ +@interface Foo +-(instancetype)init; +@end + +// RUN: env CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES=1 c-index-test -test-print-decl-attributes %s -fobjc-arc | FileCheck %s +// CHECK: ObjCInstanceMethodDecl=init:2:16 attribute(ns_consumes_self)= attribute(ns_returns_retained)= Index: tools/c-index-test/c-index-test.c =================================================================== --- tools/c-index-test/c-index-test.c +++ tools/c-index-test/c-index-test.c @@ -86,6 +86,8 @@ options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble; if (getenv("CINDEXTEST_INCLUDE_ATTRIBUTED_TYPES")) options |= CXTranslationUnit_IncludeAttributedTypes; + if (getenv("CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES")) + options |= CXTranslationUnit_VisitImplicitAttributes; return options; } @@ -1782,6 +1784,23 @@ return CXChildVisit_Recurse; } +/******************************************************************************/ +/* Declaration attributes testing */ +/******************************************************************************/ + +static enum CXChildVisitResult PrintDeclAttributes(CXCursor cursor, CXCursor p, + CXClientData d) { + if (clang_isDeclaration(cursor.kind)) { + printf("\n"); + PrintCursor(cursor, NULL); + return CXChildVisit_Recurse; + } else if (clang_isAttribute(cursor.kind)) { + printf(" "); + PrintCursor(cursor, NULL); + } + return CXChildVisit_Continue; +} + /******************************************************************************/ /* Target information testing. */ /******************************************************************************/ @@ -4793,6 +4812,9 @@ else if (argc > 2 && strcmp(argv[1], "-test-print-type-declaration") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintTypeDeclaration, 0); + else if (argc > 2 && strcmp(argv[1], "-test-print-decl-attributes") == 0) + return perform_test_load_source(argc - 2, argv + 2, "all", + PrintDeclAttributes, 0); else if (argc > 2 && strcmp(argv[1], "-test-print-bitwidth") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintBitWidth, 0); Index: tools/libclang/CIndex.cpp =================================================================== --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -1802,7 +1802,9 @@ bool CursorVisitor::VisitAttributes(Decl *D) { for (const auto *I : D->attrs()) - if (!I->isImplicit() && Visit(MakeCXCursor(I, D, TU))) + if ((TU->ParsingOptions & CXTranslationUnit_VisitImplicitAttributes || + !I->isImplicit()) && + Visit(MakeCXCursor(I, D, TU))) return true; return false;