@@ -254,7 +254,23 @@ DependencyScanningTool::initCompilerInstanceForScan(
254254 // We must do so because LLVM options parsing is done using a managed
255255 // static `GlobalParser`.
256256 llvm::cl::ResetAllOptionOccurrences ();
257- if (Invocation.parseArgs (CommandArgs, Instance->getDiags (),
257+ // Parse/tokenize arguments.
258+ std::string CommandString;
259+ for (const auto *c : CommandArgs) {
260+ CommandString.append (c);
261+ CommandString.append (" " );
262+ }
263+ SmallVector<const char *, 4 > Args;
264+ llvm::BumpPtrAllocator Alloc;
265+ llvm::StringSaver Saver (Alloc);
266+ // Ensure that we use the Windows command line parsing on Windows as we need
267+ // to ensure that we properly handle paths.
268+ if (llvm::Triple (llvm::sys::getProcessTriple ()).isOSWindows ())
269+ llvm::cl::TokenizeWindowsCommandLine (CommandString, Saver, Args);
270+ else
271+ llvm::cl::TokenizeGNUCommandLine (CommandString, Saver, Args);
272+
273+ if (Invocation.parseArgs (Args, Instance->getDiags (),
258274 nullptr , WorkingDirectory, " /tmp/foo" )) {
259275 return std::make_error_code (std::errc::invalid_argument);
260276 }
0 commit comments