[PATCH] D56655: [clangd] Fix mac buildbot failure.
    Haojian Wu via Phabricator via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Mon Jan 14 01:31:48 PST 2019
    
    
  
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: arphaman, jkorous, MaskRay, ioeric, ilya-biryukov.
Fix a use-after-free bug. The inner loop may add element to `Dependencies`
vector, which may cause memory reallocation of the vector.
Also fix an assertion, we have to take errors when llvm::Expected holds an
error.
Repository:
  rCTE Clang Tools Extra
https://reviews.llvm.org/D56655
Files:
  clangd/index/Background.cpp
Index: clangd/index/Background.cpp
===================================================================
--- clangd/index/Background.cpp
+++ clangd/index/Background.cpp
@@ -484,7 +484,7 @@
   // Goes over each dependency.
   for (size_t CurrentDependency = 0; CurrentDependency < Dependencies.size();
        CurrentDependency++) {
-    llvm::StringRef CurDependencyPath = Dependencies[CurrentDependency].Path;
+    std::string CurDependencyPath = Dependencies[CurrentDependency].Path;
     // If we have already seen this shard before(either loaded or failed) don't
     // re-try again. Since the information in the shard won't change from one TU
     // to another.
@@ -504,11 +504,18 @@
     // These are the edges in the include graph for current dependency.
     for (const auto &I : *Shard->Sources) {
       auto U = URI::parse(I.getKey());
-      if (!U)
+      if (!U) {
+        elog("Failed to parse URI {0}: {1}", I.getKey(), U.takeError());
         continue;
+      }
+
       auto AbsolutePath = URI::resolve(*U, CurDependencyPath);
-      if (!AbsolutePath)
+      if (!AbsolutePath) {
+        elog("Failed to resolve URI {0}: {1}", I.getKey(),
+             AbsolutePath.takeError());
         continue;
+      }
+
       // Add file as dependency if haven't seen before.
       if (InQueue.try_emplace(*AbsolutePath).second)
         Dependencies.emplace_back(*AbsolutePath, true);
@@ -527,6 +534,7 @@
       // Check if the source needs re-indexing.
       // Get the digest, skip it if file doesn't exist.
       auto Buf = FS->getBufferForFile(CurDependencyPath);
+
       if (!Buf) {
         elog("Couldn't get buffer for file: {0}: {1}", CurDependencyPath,
              Buf.getError().message());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56655.181499.patch
Type: text/x-patch
Size: 1722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190114/0eb63d42/attachment.bin>
    
    
More information about the cfe-commits
mailing list