diff --git a/clang-tools-extra/clangd/QueryDriverDatabase.cpp b/clang-tools-extra/clangd/QueryDriverDatabase.cpp --- 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 +#include #include #include #include @@ -238,10 +239,17 @@ tooling::CompileCommand & addSystemIncludes(tooling::CompileCommand &Cmd, llvm::ArrayRef SystemIncludes) { + std::vector 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; }