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; }
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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits