[clang-tools-extra] r352481 - [clangd] Make USRs for macros to be position independent

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 29 03:19:15 PST 2019


Author: kadircet
Date: Tue Jan 29 03:19:15 2019
New Revision: 352481

URL: http://llvm.org/viewvc/llvm-project?rev=352481&view=rev
Log:
[clangd] Make USRs for macros to be position independent

Summary:
USRs for macros were not cannonical due to usage of cursor location
instead of definition location.

Reviewers: jkorous

Subscribers: ilya-biryukov, ioeric, MaskRay, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D57228

Modified:
    clang-tools-extra/trunk/clangd/XRefs.cpp
    clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=352481&r1=352480&r2=352481&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Jan 29 03:19:15 2019
@@ -794,7 +794,8 @@ std::vector<SymbolDetails> getSymbolInfo
     SymbolDetails NewMacro;
     NewMacro.name = Macro.Name;
     llvm::SmallString<32> USR;
-    if (!index::generateUSRForMacro(NewMacro.name, Loc, SM, USR)) {
+    if (!index::generateUSRForMacro(NewMacro.name,
+                                    Macro.Info->getDefinitionLoc(), SM, USR)) {
       NewMacro.USR = USR.str();
       NewMacro.ID = SymbolID(NewMacro.USR);
     }

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp?rev=352481&r1=352480&r2=352481&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp Tue Jan 29 03:19:15 2019
@@ -149,7 +149,13 @@ TEST(SymbolInfoTests, All) {
           #define MACRO 5\nint i = MAC^RO;
         )cpp",
               {CreateExpectedSymbolDetails("MACRO", "",
-                                           "c:TestTU.cpp at 55@macro at MACRO")}},
+                                           "c:TestTU.cpp at 38@macro at MACRO")}},
+          {
+              R"cpp( // Macro reference
+          #define MACRO 5\nint i = MACRO^;
+        )cpp",
+              {CreateExpectedSymbolDetails("MACRO", "",
+                                           "c:TestTU.cpp at 38@macro at MACRO")}},
           {
               R"cpp( // Multiple symbols returned - using overloaded function name
           void foo() {}




More information about the cfe-commits mailing list