Index: clang/lib/Driver/ToolChains/BareMetal.h =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.h +++ clang/lib/Driver/ToolChains/BareMetal.h @@ -53,7 +53,6 @@ void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override; - std::string findLibCxxIncludePath(ToolChain::CXXStdlibType LibType) const; void AddClangCXXStdlibIncludeArgs( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; Index: clang/lib/Driver/ToolChains/BareMetal.cpp =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.cpp +++ clang/lib/Driver/ToolChains/BareMetal.cpp @@ -95,16 +95,23 @@ CC1Args.push_back("-nostdsysteminc"); } -std::string BareMetal::findLibCxxIncludePath(CXXStdlibType LibType) const { +void BareMetal::AddClangCXXStdlibIncludeArgs( + const ArgList &DriverArgs, ArgStringList &CC1Args) const { + if (DriverArgs.hasArg(options::OPT_nostdinc) || + DriverArgs.hasArg(options::OPT_nostdlibinc) || + DriverArgs.hasArg(options::OPT_nostdincxx)) + return; + StringRef SysRoot = getDriver().SysRoot; if (SysRoot.empty()) - return ""; + return; - switch (LibType) { + switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: { SmallString<128> Dir(SysRoot); llvm::sys::path::append(Dir, "include", "c++", "v1"); - return Dir.str(); + addSystemInclude(DriverArgs, CC1Args, Dir.str()); + break; } case ToolChain::CST_Libstdcxx: { SmallString<128> Dir(SysRoot); @@ -124,24 +131,12 @@ Version = CandidateVersion; } if (Version.Major == -1) - return ""; + return; llvm::sys::path::append(Dir, Version.Text); - return Dir.str(); + addSystemInclude(DriverArgs, CC1Args, Dir.str()); + break; } } - llvm_unreachable("unhandled LibType"); -} - -void BareMetal::AddClangCXXStdlibIncludeArgs( - const ArgList &DriverArgs, ArgStringList &CC1Args) const { - if (DriverArgs.hasArg(options::OPT_nostdinc) || - DriverArgs.hasArg(options::OPT_nostdlibinc) || - DriverArgs.hasArg(options::OPT_nostdincxx)) - return; - - std::string Path = findLibCxxIncludePath(GetCXXStdlibType(DriverArgs)); - if (!Path.empty()) - addSystemInclude(DriverArgs, CC1Args, Path); } void BareMetal::AddCXXStdlibLibArgs(const ArgList &Args, Index: clang/lib/Driver/ToolChains/CloudABI.h =================================================================== --- clang/lib/Driver/ToolChains/CloudABI.h +++ clang/lib/Driver/ToolChains/CloudABI.h @@ -50,7 +50,9 @@ GetCXXStdlibType(const llvm::opt::ArgList &Args) const override { return ToolChain::CST_Libcxx; } - std::string findLibCxxIncludePath() const override; + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; Index: clang/lib/Driver/ToolChains/CloudABI.cpp =================================================================== --- clang/lib/Driver/ToolChains/CloudABI.cpp +++ clang/lib/Driver/ToolChains/CloudABI.cpp @@ -104,10 +104,11 @@ getFilePaths().push_back(P.str()); } -std::string CloudABI::findLibCxxIncludePath() const { +void CloudABI::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { SmallString<128> P(getDriver().Dir); llvm::sys::path::append(P, "..", getTriple().str(), "include/c++/v1"); - return P.str(); + addSystemInclude(DriverArgs, CC1Args, P.str()); } void CloudABI::AddCXXStdlibLibArgs(const ArgList &Args, Index: clang/lib/Driver/ToolChains/Contiki.h =================================================================== --- clang/lib/Driver/ToolChains/Contiki.h +++ clang/lib/Driver/ToolChains/Contiki.h @@ -23,7 +23,9 @@ const llvm::opt::ArgList &Args); // No support for finding a C++ standard library yet. - std::string findLibCxxIncludePath() const override { return ""; } + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override {} void addLibStdCxxIncludePaths( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override {} Index: clang/lib/Driver/ToolChains/Gnu.h =================================================================== --- clang/lib/Driver/ToolChains/Gnu.h +++ clang/lib/Driver/ToolChains/Gnu.h @@ -316,7 +316,9 @@ const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; - virtual std::string findLibCxxIncludePath() const; + virtual void + addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const; virtual void addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const; Index: clang/lib/Driver/ToolChains/Gnu.cpp =================================================================== --- clang/lib/Driver/ToolChains/Gnu.cpp +++ clang/lib/Driver/ToolChains/Gnu.cpp @@ -2391,12 +2391,9 @@ return; switch (GetCXXStdlibType(DriverArgs)) { - case ToolChain::CST_Libcxx: { - std::string Path = findLibCxxIncludePath(); - if (!Path.empty()) - addSystemInclude(DriverArgs, CC1Args, Path); + case ToolChain::CST_Libcxx: + addLibCxxIncludePaths(DriverArgs, CC1Args); break; - } case ToolChain::CST_Libstdcxx: addLibStdCxxIncludePaths(DriverArgs, CC1Args); @@ -2404,9 +2401,12 @@ } } -std::string Generic_GCC::findLibCxxIncludePath() const { +void +Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { // FIXME: The Linux behavior would probaby be a better approach here. - return getDriver().SysRoot + "/usr/include/c++/v1"; + addSystemInclude(DriverArgs, CC1Args, + getDriver().SysRoot + "/usr/include/c++/v1"); } void Index: clang/lib/Driver/ToolChains/Haiku.h =================================================================== --- clang/lib/Driver/ToolChains/Haiku.h +++ clang/lib/Driver/ToolChains/Haiku.h @@ -27,7 +27,9 @@ return getTriple().getArch() == llvm::Triple::x86_64; } - std::string findLibCxxIncludePath() const override; + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; void addLibStdCxxIncludePaths( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; Index: clang/lib/Driver/ToolChains/Haiku.cpp =================================================================== --- clang/lib/Driver/ToolChains/Haiku.cpp +++ clang/lib/Driver/ToolChains/Haiku.cpp @@ -22,8 +22,10 @@ } -std::string Haiku::findLibCxxIncludePath() const { - return getDriver().SysRoot + "/system/develop/headers/c++/v1"; +void Haiku::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + addSystemInclude(DriverArgs, CC1Args, + getDriver().SysRoot + "/system/develop/headers/c++/v1"); } void Haiku::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, Index: clang/lib/Driver/ToolChains/Lanai.h =================================================================== --- clang/lib/Driver/ToolChains/Lanai.h +++ clang/lib/Driver/ToolChains/Lanai.h @@ -24,7 +24,9 @@ : Generic_ELF(D, Triple, Args) {} // No support for finding a C++ standard library yet. - std::string findLibCxxIncludePath() const override { return ""; } + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override {} void addLibStdCxxIncludePaths( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override {} Index: clang/lib/Driver/ToolChains/Linux.h =================================================================== --- clang/lib/Driver/ToolChains/Linux.h +++ clang/lib/Driver/ToolChains/Linux.h @@ -27,7 +27,9 @@ void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; - std::string findLibCxxIncludePath() const override; + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; void addLibStdCxxIncludePaths( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; Index: clang/lib/Driver/ToolChains/Linux.cpp =================================================================== --- clang/lib/Driver/ToolChains/Linux.cpp +++ clang/lib/Driver/ToolChains/Linux.cpp @@ -775,7 +775,8 @@ return MaxVersion ? (base + "/" + MaxVersionString).str() : ""; } -std::string Linux::findLibCxxIncludePath() const { +void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { const std::string LibCXXIncludePathCandidates[] = { DetectLibcxxIncludePath(getDriver().Dir + "/../include/c++"), // If this is a development, non-installed, clang, libcxx will @@ -787,9 +788,9 @@ if (IncludePath.empty() || !getVFS().exists(IncludePath)) continue; // Use the first candidate that exists. - return IncludePath; + addSystemInclude(DriverArgs, CC1Args, IncludePath); + return; } - return ""; } void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, Index: clang/lib/Driver/ToolChains/MipsLinux.h =================================================================== --- clang/lib/Driver/ToolChains/MipsLinux.h +++ clang/lib/Driver/ToolChains/MipsLinux.h @@ -31,7 +31,9 @@ CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; - std::string findLibCxxIncludePath() const override; + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; Index: clang/lib/Driver/ToolChains/MipsLinux.cpp =================================================================== --- clang/lib/Driver/ToolChains/MipsLinux.cpp +++ clang/lib/Driver/ToolChains/MipsLinux.cpp @@ -94,16 +94,18 @@ return ToolChain::CST_Libcxx; } -std::string MipsLLVMToolChain::findLibCxxIncludePath() const { +void MipsLLVMToolChain::addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { if (const auto &Callback = Multilibs.includeDirsCallback()) { for (std::string Path : Callback(SelectedMultilib)) { Path = getDriver().getInstalledDir() + Path + "/c++/v1"; if (llvm::sys::fs::exists(Path)) { - return Path; + addSystemInclude(DriverArgs, CC1Args, Path); + return; } } } - return ""; } void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, Index: clang/lib/Driver/ToolChains/Myriad.h =================================================================== --- clang/lib/Driver/ToolChains/Myriad.h +++ clang/lib/Driver/ToolChains/Myriad.h @@ -76,7 +76,9 @@ void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; - std::string findLibCxxIncludePath() const override; + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; void addLibStdCxxIncludePaths( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; Index: clang/lib/Driver/ToolChains/Myriad.cpp =================================================================== --- clang/lib/Driver/ToolChains/Myriad.cpp +++ clang/lib/Driver/ToolChains/Myriad.cpp @@ -242,9 +242,11 @@ addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include"); } -std::string MyriadToolChain::findLibCxxIncludePath() const { +void MyriadToolChain::addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { std::string Path(getDriver().getInstalledDir()); - return Path + "/../include/c++/v1"; + addSystemInclude(DriverArgs, CC1Args, Path + "/../include/c++/v1"); } void MyriadToolChain::addLibStdCxxIncludePaths( Index: clang/lib/Driver/ToolChains/NaCl.h =================================================================== --- clang/lib/Driver/ToolChains/NaCl.h +++ clang/lib/Driver/ToolChains/NaCl.h @@ -53,7 +53,9 @@ void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; - std::string findLibCxxIncludePath() const override; + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override; Index: clang/lib/Driver/ToolChains/NaCl.cpp =================================================================== --- clang/lib/Driver/ToolChains/NaCl.cpp +++ clang/lib/Driver/ToolChains/NaCl.cpp @@ -309,25 +309,29 @@ CmdArgs.push_back("-lc++"); } -std::string NaClToolChain::findLibCxxIncludePath() const { +void NaClToolChain::addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { const Driver &D = getDriver(); SmallString<128> P(D.Dir + "/../"); switch (getTriple().getArch()) { case llvm::Triple::arm: llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); - return P.str(); + addSystemInclude(DriverArgs, CC1Args, P.str()); + break; case llvm::Triple::x86: llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); - return P.str(); + addSystemInclude(DriverArgs, CC1Args, P.str()); + break; case llvm::Triple::x86_64: llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); - return P.str(); + addSystemInclude(DriverArgs, CC1Args, P.str()); + break; case llvm::Triple::mipsel: llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); - return P.str(); - default: - return ""; + addSystemInclude(DriverArgs, CC1Args, P.str()); + break; } } Index: clang/lib/Driver/ToolChains/NetBSD.h =================================================================== --- clang/lib/Driver/ToolChains/NetBSD.h +++ clang/lib/Driver/ToolChains/NetBSD.h @@ -60,7 +60,9 @@ CXXStdlibType GetDefaultCXXStdlibType() const override; - std::string findLibCxxIncludePath() const override; + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; void addLibStdCxxIncludePaths( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; Index: clang/lib/Driver/ToolChains/NetBSD.cpp =================================================================== --- clang/lib/Driver/ToolChains/NetBSD.cpp +++ clang/lib/Driver/ToolChains/NetBSD.cpp @@ -406,8 +406,10 @@ return ToolChain::CST_Libstdcxx; } -std::string NetBSD::findLibCxxIncludePath() const { - return getDriver().SysRoot + "/usr/include/c++/"; +void NetBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + addSystemInclude(DriverArgs, CC1Args, + getDriver().SysRoot + "/usr/include/c++/"); } void NetBSD::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, Index: clang/lib/Driver/ToolChains/PS4CPU.h =================================================================== --- clang/lib/Driver/ToolChains/PS4CPU.h +++ clang/lib/Driver/ToolChains/PS4CPU.h @@ -61,7 +61,9 @@ const llvm::opt::ArgList &Args); // No support for finding a C++ standard library yet. - std::string findLibCxxIncludePath() const override { return ""; } + void addLibCxxIncludePaths( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override {} void addLibStdCxxIncludePaths( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override {}