summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clangd/XRefs.cpp10
-rw-r--r--clang-tools-extra/unittests/clangd/XRefsTests.cpp9
2 files changed, 19 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 0f9b8a5b4af..df3bf6f9cd4 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -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();
}
}
}
diff --git a/clang-tools-extra/unittests/clangd/XRefsTests.cpp b/clang-tools-extra/unittests/clangd/XRefsTests.cpp
index a7fdc847072..0052d428ab7 100644
--- a/clang-tools-extra/unittests/clangd/XRefsTests.cpp
+++ b/clang-tools-extra/unittests/clangd/XRefsTests.cpp
@@ -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]] {};
OpenPOWER on IntegriCloud