Index: include/clang/Driver/ToolChain.h =================================================================== --- include/clang/Driver/ToolChain.h +++ include/clang/Driver/ToolChain.h @@ -21,6 +21,7 @@ #include "llvm/ADT/Triple.h" #include "llvm/MC/MCTargetOptions.h" #include "llvm/Option/Option.h" +#include "llvm/Support/Path.h" #include "llvm/Support/VersionTuple.h" #include "llvm/Target/TargetOptions.h" #include @@ -370,6 +371,12 @@ StringRef Component, bool Shared = false) const; + std::string normalizePath(StringRef Path) const { + if (!Triple.isOSWindows() || Triple.isOSCygMing()) + return llvm::sys::path::convert_to_slash(Path); + return Path; + } + // Returns /lib//. This is used by runtimes (such // as OpenMP) to find arch-specific libraries. std::string getArchSpecificLibPath() const; Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -1011,6 +1011,12 @@ .Default(SaveTempsCwd); } + llvm::Triple EffectiveTriple = computeTargetTriple(*this, TargetTriple, Args); + if (!EffectiveTriple.isOSWindows() || EffectiveTriple.isOSCygMing()) { + for (auto *Str : {&Dir, &InstalledDir, &SysRoot, &ResourceDir}) + *Str = llvm::sys::path::convert_to_slash(*Str); + } + setLTOMode(Args); // Process -fembed-bitcode= flags. Index: lib/Driver/ToolChain.cpp =================================================================== --- lib/Driver/ToolChain.cpp +++ lib/Driver/ToolChain.cpp @@ -376,9 +376,10 @@ for (const auto &LibPath : getLibraryPaths()) { SmallString<128> P(LibPath); - llvm::sys::path::append(P, Prefix + Twine("clang_rt.") + Component + Suffix); + llvm::sys::path::append(P, + Prefix + Twine("clang_rt.") + Component + Suffix); if (getVFS().exists(P)) - return P.str(); + return normalizePath(P); } StringRef Arch = getArchNameForCompilerRTLib(*this, Args); @@ -386,7 +387,7 @@ SmallString<128> Path(getCompilerRTPath()); llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" + Arch + Env + Suffix); - return Path.str(); + return normalizePath(Path); } const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args, @@ -425,7 +426,7 @@ } std::string ToolChain::GetFilePath(const char *Name) const { - return D.GetFilePath(Name, *this); + return normalizePath(D.GetFilePath(Name, *this)); } std::string ToolChain::GetProgramPath(const char *Name) const { @@ -774,12 +775,14 @@ void ToolChain::AddFilePathLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { for (const auto &LibPath : getLibraryPaths()) - if(LibPath.length() > 0) - CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); + if (LibPath.length() > 0) + CmdArgs.push_back( + Args.MakeArgString(StringRef("-L") + normalizePath(LibPath))); for (const auto &LibPath : getFilePaths()) - if(LibPath.length() > 0) - CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath)); + if (LibPath.length() > 0) + CmdArgs.push_back( + Args.MakeArgString(StringRef("-L") + normalizePath(LibPath))); } void ToolChain::AddCCKextLibArgs(const ArgList &Args, Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3496,7 +3496,8 @@ for (const auto &II : Inputs) { addDashXForInput(Args, II, CmdArgs); if (II.isFilename()) - CmdArgs.push_back(II.getFilename()); + CmdArgs.push_back( + Args.MakeArgString(TC.normalizePath(II.getFilename()))); else II.getInputArg().renderAsInput(Args, CmdArgs); } @@ -4878,7 +4879,8 @@ // Handled with other dependency code. } else if (Output.isFilename()) { CmdArgs.push_back("-o"); - CmdArgs.push_back(Output.getFilename()); + CmdArgs.push_back( + Args.MakeArgString(TC.normalizePath(Output.getFilename()))); } else { assert(Output.isNothing() && "Invalid output."); } @@ -4893,7 +4895,8 @@ for (const InputInfo &Input : FrontendInputs) { if (Input.isFilename()) - CmdArgs.push_back(Input.getFilename()); + CmdArgs.push_back( + Args.MakeArgString(TC.normalizePath(Input.getFilename()))); else Input.getInputArg().renderAsInput(Args, CmdArgs); } @@ -5586,9 +5589,10 @@ assert(Inputs.size() == 1 && "Unexpected number of inputs."); const InputInfo &Input = Inputs[0]; - const llvm::Triple &Triple = getToolChain().getEffectiveTriple(); + const ToolChain &TC = getToolChain(); + const llvm::Triple &Triple = TC.getEffectiveTriple(); const std::string &TripleStr = Triple.getTriple(); - const auto &D = getToolChain().getDriver(); + const auto &D = TC.getDriver(); // Don't warn about "clang -w -c foo.s" Args.ClaimAllArgs(options::OPT_w); @@ -5762,7 +5766,7 @@ assert(Output.isFilename() && "Unexpected lipo output."); CmdArgs.push_back("-o"); - CmdArgs.push_back(Output.getFilename()); + CmdArgs.push_back(Args.MakeArgString(TC.normalizePath(Output.getFilename()))); const llvm::Triple &T = getToolChain().getTriple(); if (Args.hasArg(options::OPT_gsplit_dwarf) && @@ -5772,7 +5776,7 @@ } assert(Input.isFilename() && "Invalid input."); - CmdArgs.push_back(Input.getFilename()); + CmdArgs.push_back(Args.MakeArgString(TC.normalizePath(Input.getFilename()))); const char *Exec = getToolChain().getDriver().getClangProgramPath(); C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); Index: lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- lib/Driver/ToolChains/CommonArgs.cpp +++ lib/Driver/ToolChains/CommonArgs.cpp @@ -163,7 +163,7 @@ // Add filenames immediately. if (II.isFilename()) { - CmdArgs.push_back(II.getFilename()); + CmdArgs.push_back(Args.MakeArgString(TC.normalizePath(II.getFilename()))); continue; } Index: lib/Driver/ToolChains/Gnu.cpp =================================================================== --- lib/Driver/ToolChains/Gnu.cpp +++ lib/Driver/ToolChains/Gnu.cpp @@ -1699,7 +1699,7 @@ if (GCCToolchainDir.back() == '/') GCCToolchainDir = GCCToolchainDir.drop_back(); // remove the / - Prefixes.push_back(GCCToolchainDir); + Prefixes.push_back(llvm::sys::path::convert_to_slash(GCCToolchainDir)); } else { // If we have a SysRoot, try that first. if (!D.SysRoot.empty()) {