From c068e9094a31e2372a0dcac7f570a545a6f78634 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 24 Apr 2018 08:39:46 +0000 Subject: [PATCH] [libclang] Only mark CXCursors for explicit attributes with a type All attributes have a source range associated with it. However, implicit attributes are added by the compiler, and not added because the user wrote something in the input. So no token type should be set to CXCursor_*Attr. The problem was visible when a class gets marked by e.g. MSInheritanceAttr, which has the full CXXRecordDecl's range as its own range. The effect of marking that range as CXCursor_UnexposedAttr was that all cursors for the record decl, including all child decls, would become CXCursor_UnexposedAttr. llvm-svn: 330692 --- clang/test/Index/annotate-tokens-unexposed.cpp | 20 ++++++++++++++++++++ clang/tools/libclang/CIndex.cpp | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 clang/test/Index/annotate-tokens-unexposed.cpp diff --git a/clang/test/Index/annotate-tokens-unexposed.cpp b/clang/test/Index/annotate-tokens-unexposed.cpp new file mode 100644 index 0000000..3e5d794 --- /dev/null +++ b/clang/test/Index/annotate-tokens-unexposed.cpp @@ -0,0 +1,20 @@ +// RUN: c-index-test -test-annotate-tokens=%s:1:1:16:1 %s -target x86_64-pc-windows-msvc | FileCheck %s +class Foo +{ +public: + void step(int v); + Foo(); +}; + +void bar() +{ + // Introduce a MSInheritanceAttr node on the CXXRecordDecl for Foo. The + // existance of this attribute should not mark all cursors for tokens in + // Foo as UnexposedAttr. + &Foo::step; +} + +Foo::Foo() +{} + +// CHECK-NOT: UnexposedAttr= diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 480e00e..497a3ca 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -1796,7 +1796,7 @@ bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) { bool CursorVisitor::VisitAttributes(Decl *D) { for (const auto *I : D->attrs()) - if (Visit(MakeCXCursor(I, D, TU))) + if (!I->isImplicit() && Visit(MakeCXCursor(I, D, TU))) return true; return false; -- 2.7.4