50
50
#include " llvm/Support/Regex.h"
51
51
#include " llvm/Support/ScopedPrinter.h"
52
52
#include < algorithm>
53
+ #include < iterator>
53
54
#include < map>
54
55
#include < string>
55
56
#include < vector>
@@ -238,10 +239,17 @@ extractSystemIncludesAndTarget(llvm::SmallString<128> Driver,
238
239
tooling::CompileCommand &
239
240
addSystemIncludes (tooling::CompileCommand &Cmd,
240
241
llvm::ArrayRef<std::string> SystemIncludes) {
242
+ std::vector<std::string> ToAppend;
241
243
for (llvm::StringRef Include : SystemIncludes) {
242
244
// 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 ()));
245
253
}
246
254
return Cmd;
247
255
}
@@ -254,7 +262,9 @@ tooling::CompileCommand &setTarget(tooling::CompileCommand &Cmd,
254
262
if (Arg == " -target" || Arg.startswith (" --target=" ))
255
263
return Cmd;
256
264
}
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);
258
268
}
259
269
return Cmd;
260
270
}
0 commit comments