Skip to content

Commit 175833e

Browse files
[clangd] Handle '--' in QueryDriverDatabase
Fixes clangd/clangd#1100, a regression from D116721. Differential Revision: https://reviews.llvm.org/D126274
1 parent 4a3e2af commit 175833e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

clang-tools-extra/clangd/QueryDriverDatabase.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "llvm/Support/Regex.h"
5151
#include "llvm/Support/ScopedPrinter.h"
5252
#include <algorithm>
53+
#include <iterator>
5354
#include <map>
5455
#include <string>
5556
#include <vector>
@@ -238,10 +239,17 @@ extractSystemIncludesAndTarget(llvm::SmallString<128> Driver,
238239
tooling::CompileCommand &
239240
addSystemIncludes(tooling::CompileCommand &Cmd,
240241
llvm::ArrayRef<std::string> SystemIncludes) {
242+
std::vector<std::string> ToAppend;
241243
for (llvm::StringRef Include : SystemIncludes) {
242244
// FIXME(kadircet): This doesn't work when we have "--driver-mode=cl"
243-
Cmd.CommandLine.push_back("-isystem");
244-
Cmd.CommandLine.push_back(Include.str());
245+
ToAppend.push_back("-isystem");
246+
ToAppend.push_back(Include.str());
247+
}
248+
if (!ToAppend.empty()) {
249+
// Just append when `--` isn't present.
250+
auto InsertAt = llvm::find(Cmd.CommandLine, "--");
251+
Cmd.CommandLine.insert(InsertAt, std::make_move_iterator(ToAppend.begin()),
252+
std::make_move_iterator(ToAppend.end()));
245253
}
246254
return Cmd;
247255
}
@@ -254,7 +262,9 @@ tooling::CompileCommand &setTarget(tooling::CompileCommand &Cmd,
254262
if (Arg == "-target" || Arg.startswith("--target="))
255263
return Cmd;
256264
}
257-
Cmd.CommandLine.push_back("--target=" + Target);
265+
// Just append when `--` isn't present.
266+
auto InsertAt = llvm::find(Cmd.CommandLine, "--");
267+
Cmd.CommandLine.insert(InsertAt, "--target=" + Target);
258268
}
259269
return Cmd;
260270
}

0 commit comments

Comments
 (0)