[clang-tools-extra] 175833e - [clangd] Handle '--' in QueryDriverDatabase

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Tue May 24 10:10:58 PDT 2022


Author: Nathan Ridge
Date: 2022-05-24T13:10:41-04:00
New Revision: 175833ed6f62b697ce6248930da54e4ddb7f4c00

URL: https://github.com/llvm/llvm-project/commit/175833ed6f62b697ce6248930da54e4ddb7f4c00
DIFF: https://github.com/llvm/llvm-project/commit/175833ed6f62b697ce6248930da54e4ddb7f4c00.diff

LOG: [clangd] Handle '--' in QueryDriverDatabase

Fixes https://github.com/clangd/clangd/issues/1100,
a regression from D116721.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/QueryDriverDatabase.cpp b/clang-tools-extra/clangd/QueryDriverDatabase.cpp
index 477087323c7d3..e96912c6290c7 100644
--- a/clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ b/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 @@ extractSystemIncludesAndTarget(llvm::SmallString<128> Driver,
 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 @@ tooling::CompileCommand &setTarget(tooling::CompileCommand &Cmd,
       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;
 }


        


More information about the cfe-commits mailing list