[PATCH] D126274: [clangd] Handle '--' in QueryDriverDatabase

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 23 23:13:37 PDT 2022


nridge created this revision.
nridge added reviewers: sammccall, kadircet.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Fixes https://github.com/clangd/clangd/issues/1100,
a regression from D116721 <https://reviews.llvm.org/D116721>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126274

Files:
  clang-tools-extra/clangd/QueryDriverDatabase.cpp


Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===================================================================
--- clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -50,6 +50,7 @@
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include <algorithm>
+#include <iterator>
 #include <map>
 #include <string>
 #include <vector>
@@ -238,10 +239,17 @@
 tooling::CompileCommand &
 addSystemIncludes(tooling::CompileCommand &Cmd,
                   llvm::ArrayRef<std::string> SystemIncludes) {
+  std::vector<std::string> ToAppend;
   for (llvm::StringRef Include : SystemIncludes) {
     // FIXME(kadircet): This doesn't work when we have "--driver-mode=cl"
-    Cmd.CommandLine.push_back("-isystem");
-    Cmd.CommandLine.push_back(Include.str());
+    ToAppend.push_back("-isystem");
+    ToAppend.push_back(Include.str());
+  }
+  if (!ToAppend.empty()) {
+    // Just append when `--` isn't present.
+    auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+    Cmd.CommandLine.insert(InsertAt, std::make_move_iterator(ToAppend.begin()),
+                           std::make_move_iterator(ToAppend.end()));
   }
   return Cmd;
 }
@@ -254,7 +262,9 @@
       if (Arg == "-target" || Arg.startswith("--target="))
         return Cmd;
     }
-    Cmd.CommandLine.push_back("--target=" + Target);
+    // Just append when `--` isn't present.
+    auto InsertAt = llvm::find(Cmd.CommandLine, "--");
+    Cmd.CommandLine.insert(InsertAt, "--target=" + Target);
   }
   return Cmd;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126274.431596.patch
Type: text/x-patch
Size: 1570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220524/9609dd81/attachment.bin>


More information about the cfe-commits mailing list