diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index 57a668650e6b..c302d647b973 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -95,16 +95,23 @@ void BareMetal::addClangTargetOptions(const ArgList &DriverArgs, 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 @@ std::string BareMetal::findLibCxxIncludePath(CXXStdlibType LibType) const { 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, diff --git a/clang/lib/Driver/ToolChains/BareMetal.h b/clang/lib/Driver/ToolChains/BareMetal.h index 0bed63332cad..43a6a8b4bec3 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.h +++ b/clang/lib/Driver/ToolChains/BareMetal.h @@ -53,7 +53,6 @@ public: 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; diff --git a/clang/lib/Driver/ToolChains/CloudABI.cpp b/clang/lib/Driver/ToolChains/CloudABI.cpp index cdf807f7f91f..3aa55de7ea1b 100644 --- a/clang/lib/Driver/ToolChains/CloudABI.cpp +++ b/clang/lib/Driver/ToolChains/CloudABI.cpp @@ -104,10 +104,11 @@ CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple, 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, diff --git a/clang/lib/Driver/ToolChains/CloudABI.h b/clang/lib/Driver/ToolChains/CloudABI.h index a284eb3dc0a4..7464c5954555 100644 --- a/clang/lib/Driver/ToolChains/CloudABI.h +++ b/clang/lib/Driver/ToolChains/CloudABI.h @@ -50,7 +50,9 @@ public: 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; diff --git a/clang/lib/Driver/ToolChains/Contiki.h b/clang/lib/Driver/ToolChains/Contiki.h index f6e15073887b..86d59ac92b16 100644 --- a/clang/lib/Driver/ToolChains/Contiki.h +++ b/clang/lib/Driver/ToolChains/Contiki.h @@ -23,7 +23,9 @@ public: 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 {} diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index e10e14fb23b6..a50e5bd6632a 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2391,12 +2391,9 @@ void Generic_GCC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, 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 @@ void Generic_GCC::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, } } -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 diff --git a/clang/lib/Driver/ToolChains/Gnu.h b/clang/lib/Driver/ToolChains/Gnu.h index cc9b4a334557..a053e6f213c6 100644 --- a/clang/lib/Driver/ToolChains/Gnu.h +++ b/clang/lib/Driver/ToolChains/Gnu.h @@ -316,7 +316,9 @@ protected: 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; diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp index 284d269a0c1b..12461ec9c4bd 100644 --- a/clang/lib/Driver/ToolChains/Haiku.cpp +++ b/clang/lib/Driver/ToolChains/Haiku.cpp @@ -22,8 +22,10 @@ Haiku::Haiku(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) } -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, diff --git a/clang/lib/Driver/ToolChains/Haiku.h b/clang/lib/Driver/ToolChains/Haiku.h index 8b5b48e59023..a12a48e00976 100644 --- a/clang/lib/Driver/ToolChains/Haiku.h +++ b/clang/lib/Driver/ToolChains/Haiku.h @@ -27,7 +27,9 @@ public: 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; diff --git a/clang/lib/Driver/ToolChains/Lanai.h b/clang/lib/Driver/ToolChains/Lanai.h index 4ce658dc7775..bb92bfaea7e2 100644 --- a/clang/lib/Driver/ToolChains/Lanai.h +++ b/clang/lib/Driver/ToolChains/Lanai.h @@ -24,7 +24,9 @@ public: : 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 {} diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index f135c19e540f..c9544a39c203 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -775,7 +775,8 @@ static std::string DetectLibcxxIncludePath(StringRef base) { 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 @@ std::string Linux::findLibCxxIncludePath() const { 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, diff --git a/clang/lib/Driver/ToolChains/Linux.h b/clang/lib/Driver/ToolChains/Linux.h index 9778c1832ccc..22dbbecf6b96 100644 --- a/clang/lib/Driver/ToolChains/Linux.h +++ b/clang/lib/Driver/ToolChains/Linux.h @@ -27,7 +27,9 @@ public: 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; diff --git a/clang/lib/Driver/ToolChains/MipsLinux.cpp b/clang/lib/Driver/ToolChains/MipsLinux.cpp index b394208336ed..2f1c8b2f0c70 100644 --- a/clang/lib/Driver/ToolChains/MipsLinux.cpp +++ b/clang/lib/Driver/ToolChains/MipsLinux.cpp @@ -94,16 +94,18 @@ MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const { 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, diff --git a/clang/lib/Driver/ToolChains/MipsLinux.h b/clang/lib/Driver/ToolChains/MipsLinux.h index fa82efbbfc8f..d4b476d883e6 100644 --- a/clang/lib/Driver/ToolChains/MipsLinux.h +++ b/clang/lib/Driver/ToolChains/MipsLinux.h @@ -31,7 +31,9 @@ public: 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; diff --git a/clang/lib/Driver/ToolChains/Myriad.cpp b/clang/lib/Driver/ToolChains/Myriad.cpp index 2c0b3162588d..2b4c1d165576 100644 --- a/clang/lib/Driver/ToolChains/Myriad.cpp +++ b/clang/lib/Driver/ToolChains/Myriad.cpp @@ -242,9 +242,11 @@ void MyriadToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, 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( diff --git a/clang/lib/Driver/ToolChains/Myriad.h b/clang/lib/Driver/ToolChains/Myriad.h index 4c213c726219..33307c3f871a 100644 --- a/clang/lib/Driver/ToolChains/Myriad.h +++ b/clang/lib/Driver/ToolChains/Myriad.h @@ -76,7 +76,9 @@ public: 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; diff --git a/clang/lib/Driver/ToolChains/NaCl.cpp b/clang/lib/Driver/ToolChains/NaCl.cpp index 128478d63871..2e5365b4814d 100644 --- a/clang/lib/Driver/ToolChains/NaCl.cpp +++ b/clang/lib/Driver/ToolChains/NaCl.cpp @@ -309,25 +309,29 @@ void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, 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; } } diff --git a/clang/lib/Driver/ToolChains/NaCl.h b/clang/lib/Driver/ToolChains/NaCl.h index 31af3a53ad3c..e0885b526d70 100644 --- a/clang/lib/Driver/ToolChains/NaCl.h +++ b/clang/lib/Driver/ToolChains/NaCl.h @@ -53,7 +53,9 @@ public: 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; diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp b/clang/lib/Driver/ToolChains/NetBSD.cpp index 0db6578f7407..55fefdf26f6f 100644 --- a/clang/lib/Driver/ToolChains/NetBSD.cpp +++ b/clang/lib/Driver/ToolChains/NetBSD.cpp @@ -406,8 +406,10 @@ ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const { 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, diff --git a/clang/lib/Driver/ToolChains/NetBSD.h b/clang/lib/Driver/ToolChains/NetBSD.h index e98df72ce65c..49e3a58d02c3 100644 --- a/clang/lib/Driver/ToolChains/NetBSD.h +++ b/clang/lib/Driver/ToolChains/NetBSD.h @@ -60,7 +60,9 @@ public: 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; diff --git a/clang/lib/Driver/ToolChains/PS4CPU.h b/clang/lib/Driver/ToolChains/PS4CPU.h index e507edbad4d5..93752c407931 100644 --- a/clang/lib/Driver/ToolChains/PS4CPU.h +++ b/clang/lib/Driver/ToolChains/PS4CPU.h @@ -61,7 +61,9 @@ public: 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 {}