Author: Kadir Cetinkaya Date: 2021-10-25T13:16:14+02:00 New Revision: 9ab9caf214f47ea0ccf5cd3eb0aef2fcb88bd6e1
URL: https://github.com/llvm/llvm-project/commit/9ab9caf214f47ea0ccf5cd3eb0aef2fcb88bd6e1 DIFF: https://github.com/llvm/llvm-project/commit/9ab9caf214f47ea0ccf5cd3eb0aef2fcb88bd6e1.diff LOG: [clang] Visit enum base specifiers in libIndex Fixes https://github.com/clangd/clangd/issues/878. Differential Revision: https://reviews.llvm.org/D111260 Added: Modified: clang-tools-extra/clangd/unittests/XRefsTests.cpp clang/lib/Index/IndexDecl.cpp clang/unittests/Index/IndexTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp index 99a6b6e9d8bee..802367645c859 100644 --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -1966,6 +1966,20 @@ TEST(FindReferences, WithinAST) { [[f^oo]](s); } )cpp", + + // Enum base + R"cpp( + typedef int $def[[MyTypeD^ef]]; + enum MyEnum : [[MyTy^peDef]] { }; + )cpp", + R"cpp( + typedef int $def[[MyType^Def]]; + enum MyEnum : [[MyTypeD^ef]]; + )cpp", + R"cpp( + using $def[[MyTypeD^ef]] = int; + enum MyEnum : [[MyTy^peDef]] { }; + )cpp", }; for (const char *Test : Tests) checkFindRefs(Test); diff --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp index 00adb3644ff25..3139aedaf01d4 100644 --- a/clang/lib/Index/IndexDecl.cpp +++ b/clang/lib/Index/IndexDecl.cpp @@ -8,6 +8,7 @@ #include "IndexingContext.h" #include "clang/AST/Attr.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclVisitor.h" #include "clang/Index/IndexDataConsumer.h" @@ -372,6 +373,15 @@ class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> { return true; } + bool VisitEnumDecl(const EnumDecl *ED) { + TRY_TO(VisitTagDecl(ED)); + // Indexing for enumdecl itself is handled inside TagDecl, we just want to + // visit integer-base here, which is diff erent than other TagDecl bases. + if (auto *TSI = ED->getIntegerTypeSourceInfo()) + IndexCtx.indexTypeSourceInfo(TSI, ED, ED, /*isBase=*/true); + return true; + } + bool handleReferencedProtocols(const ObjCProtocolList &ProtList, const ObjCContainerDecl *ContD, SourceLocation SuperLoc) { diff --git a/clang/unittests/Index/IndexTests.cpp b/clang/unittests/Index/IndexTests.cpp index 24230c68fa22f..88ad63b97b92a 100644 --- a/clang/unittests/Index/IndexTests.cpp +++ b/clang/unittests/Index/IndexTests.cpp @@ -377,6 +377,21 @@ TEST(IndexTest, RelationBaseOf) { Not(HasRole(SymbolRole::RelationBaseOf))))); } +TEST(IndexTest, EnumBase) { + std::string Code = R"cpp( + typedef int MyTypedef; + enum Foo : MyTypedef; + enum Foo : MyTypedef {}; + )cpp"; + auto Index = std::make_shared<Indexer>(); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code); + EXPECT_THAT( + Index->Symbols, + AllOf(Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference), + WrittenAt(Position(3, 16)))), + Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference), + WrittenAt(Position(4, 16)))))); +} } // namespace } // namespace index } // namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits