diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Driver/ToolChains.cpp | 28 | ||||
| -rw-r--r-- | clang/test/Driver/linux-header-search.cpp | 23 |
2 files changed, 45 insertions, 6 deletions
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index c0563469c1c..e364fa7ba31 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -2945,9 +2945,24 @@ void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, // Check if libc++ has been enabled and provide its include paths if so. if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) { - // libc++ is always installed at a fixed path on Linux currently. - addSystemInclude(DriverArgs, CC1Args, - getDriver().SysRoot + "/usr/include/c++/v1"); + const std::string LibCXXIncludePathCandidates[] = { + // The primary location is within the Clang installation. + // FIXME: We shouldn't hard code 'v1' here to make Clang future proof to + // newer ABI versions. + getDriver().Dir + "/../include/c++/v1", + + // We also check the system as for a long time this is the only place Clang looked. + // FIXME: We should really remove this. It doesn't make any sense. + getDriver().SysRoot + "/usr/include/c++/v1" + }; + for (unsigned i = 0; i < llvm::array_lengthof(LibCXXIncludePathCandidates); + ++i) { + if (!llvm::sys::fs::exists(LibCXXIncludePathCandidates[i])) + continue; + // Add the first candidate that exists. + addSystemInclude(DriverArgs, CC1Args, LibCXXIncludePathCandidates[i]); + break; + } return; } @@ -2971,7 +2986,7 @@ void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, MIPSABIDirSuffix, DriverArgs, CC1Args)) return; - const std::string IncludePathCandidates[] = { + const std::string LibStdCXXIncludePathCandidates[] = { // Gentoo is weird and places its headers inside the GCC install, so if the // first attempt to find the headers fails, try these patterns. InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." + @@ -2984,8 +2999,9 @@ void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, LibDir.str() + "/../include/c++", }; - for (unsigned i = 0; i < llvm::array_lengthof(IncludePathCandidates); ++i) { - if (addLibStdCXXIncludePaths(IncludePathCandidates[i], + for (unsigned i = 0; i < llvm::array_lengthof(LibStdCXXIncludePathCandidates); + ++i) { + if (addLibStdCXXIncludePaths(LibStdCXXIncludePathCandidates[i], TripleStr + MIPSABIDirSuffix + BiarchSuffix, DriverArgs, CC1Args)) break; diff --git a/clang/test/Driver/linux-header-search.cpp b/clang/test/Driver/linux-header-search.cpp index 8955ed71d3c..84bfd584809 100644 --- a/clang/test/Driver/linux-header-search.cpp +++ b/clang/test/Driver/linux-header-search.cpp @@ -1,6 +1,29 @@ // General tests that the header search paths detected by the driver and passed // to CC1 are sane. // +// Test a simulated installation of libc++ on Linux, both through sysroot and +// the installation path of Clang. +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-unknown-linux-gnu \ +// RUN: -stdlib=libc++ \ +// RUN: -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \ +// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree \ +// RUN: | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-SYSROOT %s +// CHECK-BASIC-LIBCXX-SYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-BASIC-LIBCXX-SYSROOT: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1" +// CHECK-BASIC-LIBCXX-SYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ +// RUN: -target x86_64-unknown-linux-gnu \ +// RUN: -stdlib=libc++ \ +// RUN: -ccc-install-dir %S/Inputs/basic_linux_libcxx_tree/usr/bin \ +// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree \ +// RUN: | FileCheck --check-prefix=CHECK-BASIC-LIBCXX-INSTALL %s +// CHECK-BASIC-LIBCXX-INSTALL: "{{[^"]*}}clang{{[^"]*}}" "-cc1" +// CHECK-BASIC-LIBCXX-INSTALL: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1" +// CHECK-BASIC-LIBCXX-INSTALL: "-internal-isystem" "[[SYSROOT]]/usr/local/include" +// // Test a very broken version of multiarch that shipped in Ubuntu 11.04. // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \ // RUN: -target i386-unknown-linux \ |

