Author: hokein Date: Tue Mar 13 05:30:59 2018 New Revision: 327387 URL: http://llvm.org/viewvc/llvm-project?rev=327387&view=rev Log: [clangd] Fix irrelevant declaratations in goto definition (on macros).
Summary: DeclrationAndMacrosFinder will find some declarations (not macro!) that are referened inside the macro somehow, isSearchedLocation() is not sufficient, we don't know whether the searched source location is macro or not. Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44293 Modified: clang-tools-extra/trunk/clangd/XRefs.cpp clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Modified: clang-tools-extra/trunk/clangd/XRefs.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=327387&r1=327386&r2=327387&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/XRefs.cpp (original) +++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Mar 13 05:30:59 2018 @@ -127,6 +127,16 @@ private: MacroInfo *MacroInf = MacroDef.getMacroInfo(); if (MacroInf) { MacroInfos.push_back(MacroDecl{IdentifierInfo->getName(), MacroInf}); + // Clear all collected delcarations if this is a macro search. + // + // In theory, there should be no declarataions being collected when we + // search a source location that refers to a macro. + // The occurrence location returned by `handleDeclOccurence` is + // limited (FID, Offset are from expansion location), we will collect + // all declarations inside the macro. + // + // FIXME: Avoid adding decls from inside macros in handlDeclOccurence. + Decls.clear(); } } } Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=327387&r1=327386&r2=327387&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Tue Mar 13 05:30:59 2018 @@ -213,6 +213,15 @@ TEST(GoToDefinition, All) { #undef macro )cpp", + R"cpp(// Macro + class TTT { public: int a; }; + #define [[FF(S) if (int b = S.a) {}]] + void f() { + TTT t; + F^F(t); + } + )cpp", + R"cpp(// Forward class declaration class Foo; class [[Foo]] {}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits