diff options
| author | Shoaib Meenai <smeenai@fb.com> | 2019-08-06 06:48:43 +0000 |
|---|---|---|
| committer | Shoaib Meenai <smeenai@fb.com> | 2019-08-06 06:48:43 +0000 |
| commit | b50e8c592789bfecb85dca9067c0853ad4d30199 (patch) | |
| tree | 77571da969bbc76cef12adbe0d0d3e7af449f7a0 /clang/lib | |
| parent | c37022b22a8a65faf3ff4d2d37c1ff4d16b6e6a8 (diff) | |
| download | bcm5719-llvm-b50e8c592789bfecb85dca9067c0853ad4d30199.tar.gz bcm5719-llvm-b50e8c592789bfecb85dca9067c0853ad4d30199.zip | |
[Driver] Introduce -stdlib++-isystem
There are times when we wish to explicitly control the C++ standard
library search paths used by the driver. For example, when we're
building against the Android NDK, we might want to use the NDK's C++
headers (which have a custom inline namespace) even if we have C++
headers installed next to the driver. We might also be building against
a non-standard directory layout and wanting to specify the C++ standard
library include directories explicitly.
We could accomplish this by passing -nostdinc++ and adding an explicit
-isystem for our custom search directories. However, users of our
toolchain may themselves want to use -nostdinc++ and a custom C++ search
path (libc++'s build does this, for example), and our added -isystem
won't respect the -nostdinc++, leading to multiple C++ header
directories on the search path, which causes build failures.
Add a new driver option -stdlib++-isystem to support this use case.
Passing this option suppresses adding the default C++ library include
paths in the driver, and it also respects -nostdinc++ to allow users to
still override the C++ library paths themselves.
It's a bit unfortunate that we end up with both -stdlib++-isystem and
-cxx-isystem, but their semantics differ significantly. -cxx-isystem is
unaffected by -nostdinc++ and is added to the end of the search path
(which is not appropriate for C++ standard library headers, since they
often #include_next into other system headers), while -stdlib++-isystem
respects -nostdinc++, is added to the beginning of the search path, and
suppresses the default C++ library include paths.
Differential Revision: https://reviews.llvm.org/D64089
llvm-svn: 367982
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Driver/ToolChain.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 17 |
2 files changed, 22 insertions, 5 deletions
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index b1fddb0af55..d0513a75cae 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -832,6 +832,16 @@ void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ); } +void ToolChain::AddClangCXXStdlibIsystemArgs( + const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + DriverArgs.ClaimAllArgs(options::OPT_stdlibxx_isystem); + if (!DriverArgs.hasArg(options::OPT_nostdincxx)) + for (const auto &P : + DriverArgs.getAllArgValues(options::OPT_stdlibxx_isystem)) + addSystemInclude(DriverArgs, CC1Args, P); +} + bool ToolChain::ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const { return getDriver().CCCIsCXX() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4681e013893..bac6cff62f0 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1235,6 +1235,9 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, // Do not claim the argument so that the use of the argument does not // silently go unnoticed on toolchains which do not honour the option. continue; + } else if (A->getOption().matches(options::OPT_stdlibxx_isystem)) { + // Translated to -internal-isystem by the driver, no need to pass to cc1. + continue; } // Not translated, render as usual. @@ -1289,11 +1292,15 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, // of an offloading programming model. // Add C++ include arguments, if needed. - if (types::isCXX(Inputs[0].getType())) - forAllAssociatedToolChains(C, JA, getToolChain(), - [&Args, &CmdArgs](const ToolChain &TC) { - TC.AddClangCXXStdlibIncludeArgs(Args, CmdArgs); - }); + if (types::isCXX(Inputs[0].getType())) { + bool HasStdlibxxIsystem = Args.hasArg(options::OPT_stdlibxx_isystem); + forAllAssociatedToolChains( + C, JA, getToolChain(), + [&Args, &CmdArgs, HasStdlibxxIsystem](const ToolChain &TC) { + HasStdlibxxIsystem ? TC.AddClangCXXStdlibIsystemArgs(Args, CmdArgs) + : TC.AddClangCXXStdlibIncludeArgs(Args, CmdArgs); + }); + } // Add system include arguments for all targets but IAMCU. if (!IsIAMCU) |

