[clang-tools-extra] r317585 - [clangd] Fix opening declarations located in non-preamble inclusion

Marc-Andre Laperle via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 7 08:16:45 PST 2017


Author: malaperle
Date: Tue Nov  7 08:16:45 2017
New Revision: 317585

URL: http://llvm.org/viewvc/llvm-project?rev=317585&view=rev
Log:
[clangd] Fix opening declarations located in non-preamble inclusion

Summary:
When an inclusion is not processed as part of the preamble, its path is
not made into an absolute path as part of the precompiled header code
(adjustFilenameForRelocatableAST in ASTWriter.cpp). Because of this,
when we convert a Decl location to retrieve the file name with
FileEntry->getName(), it is possible for this path to be relative.
Instead, we should try to use tryGetRealPathName first which returns
an absolute path.

Fixes bug 35217.

Reviewers: sammccall, ilya-biryukov, rwols, Nebiroth

Reviewed By: sammccall

Subscribers: cfe-commits, ilya-biryukov

Tags: #clang-tools-extra

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

Modified:
    clang-tools-extra/trunk/clangd/ClangdUnit.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=317585&r1=317584&r2=317585&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Nov  7 08:16:45 2017
@@ -965,10 +965,15 @@ private:
     End.character = SourceMgr.getSpellingColumnNumber(LocEnd) - 1;
     Range R = {Begin, End};
     Location L;
-    L.uri = URI::fromFile(
-        SourceMgr.getFilename(SourceMgr.getSpellingLoc(LocStart)));
-    L.range = R;
-    DeclarationLocations.push_back(L);
+    if (const FileEntry *F =
+            SourceMgr.getFileEntryForID(SourceMgr.getFileID(LocStart))) {
+      StringRef FilePath = F->tryGetRealPathName();
+      if (FilePath.empty())
+        FilePath = F->getName();
+      L.uri = URI::fromFile(FilePath);
+      L.range = R;
+      DeclarationLocations.push_back(L);
+    }
   }
 
   void finish() override {




More information about the cfe-commits mailing list