[PATCH] D44293: [clangd] Fix irrelevant declaratations in goto definition (on macros).

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 13 04:10:23 PDT 2018


hokein updated this revision to Diff 138147.
hokein marked an inline comment as done.
hokein added a comment.

Address review comment.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44293

Files:
  clangd/XRefs.cpp
  unittests/clangd/XRefsTests.cpp


Index: unittests/clangd/XRefsTests.cpp
===================================================================
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -213,6 +213,15 @@
         #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 {}]];
Index: clangd/XRefs.cpp
===================================================================
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -126,6 +126,16 @@
         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: Exclude declarations from macros.
+          Decls.clear();
         }
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44293.138147.patch
Type: text/x-patch
Size: 1390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180313/4704217f/attachment.bin>


More information about the cfe-commits mailing list