diff options
author | James Y Knight <jyknight@google.com> | 2019-05-22 20:39:51 +0000 |
---|---|---|
committer | James Y Knight <jyknight@google.com> | 2019-05-22 20:39:51 +0000 |
commit | b2ece169ed609b9111c290254d831101d21cbf8f (patch) | |
tree | 823071454efcb255f7f87d11641e98717c4d45fa /clang/lib/Driver/ToolChains/Darwin.cpp | |
parent | 275a55cb5a622491269bf89ba717d73766acaac6 (diff) | |
download | bcm5719-llvm-b2ece169ed609b9111c290254d831101d21cbf8f.tar.gz bcm5719-llvm-b2ece169ed609b9111c290254d831101d21cbf8f.zip |
Add back --sysroot support for darwin header search.
Before e97b5f5cf37e ([clang][Darwin] Refactor header search path logic
into the driver), both --sysroot and -isysroot worked to specify where
to look for system and C++ headers on Darwin. However, that change
caused clang to start ignoring --sysroot.
This fixes the regression, and adds tests.
(I also note that on all other platforms, clang seems to almost
completely ignore -isysroot, but that's another issue...)
Differential Revision: https://reviews.llvm.org/D62268
llvm-svn: 361429
Diffstat (limited to 'clang/lib/Driver/ToolChains/Darwin.cpp')
-rw-r--r-- | clang/lib/Driver/ToolChains/Darwin.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 3596be41607..478e1111e18 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1805,13 +1805,21 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { } } +// Returns the effective header sysroot path to use. This comes either from +// -isysroot or --sysroot. +llvm::StringRef DarwinClang::GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const { + if(DriverArgs.hasArg(options::OPT_isysroot)) + return DriverArgs.getLastArgValue(options::OPT_isysroot); + if (!getDriver().SysRoot.empty()) + return getDriver().SysRoot; + return "/"; +} + void DarwinClang::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const { const Driver &D = getDriver(); - llvm::StringRef Sysroot = "/"; - if (const Arg *A = DriverArgs.getLastArg(options::OPT_isysroot)) - Sysroot = A->getValue(); + llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs); bool NoStdInc = DriverArgs.hasArg(options::OPT_nostdinc); bool NoStdlibInc = DriverArgs.hasArg(options::OPT_nostdlibinc); @@ -1897,12 +1905,7 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs( DriverArgs.hasArg(options::OPT_nostdincxx)) return; - llvm::SmallString<128> Sysroot; - if (const Arg *A = DriverArgs.getLastArg(options::OPT_isysroot)) { - Sysroot = A->getValue(); - } else { - Sysroot = "/"; - } + llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs); switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: { |