yan12125 updated this revision to Diff 10.
yan12125 added a comment.
Add a test and fix repeated call to defaultSysRoot()
Repository:
rL LLVM
https://reviews.llvm.org/D35137
Files:
include/clang/Driver/Driver.h
lib/Driver/Driver.cpp
lib/Driver/ToolChains/Linux.cpp
lib/Driver/ToolChains/Linux.h
test/Driver/linux-header-search.cpp
Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -29,6 +29,18 @@
// 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: -isysroot %S/Inputs/basic_linux_libcxx_tree \
+// RUN: --gcc-toolchain="" \
+// RUN: | FileCheck --check-prefix=CHECK-ISYSROOT %s
+// CHECK-ISYSROOT: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
+// CHECK-ISYSROOT: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-ISYSROOT: "-internal-isystem" "[[SYSROOT]]/usr/bin/../include/c++/v1"
+// CHECK-ISYSROOT: "-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_tree/usr/bin \
// RUN: --sysroot=%S/Inputs/basic_linux_libcxxv2_tree \
// RUN: --gcc-toolchain="" \
Index: lib/Driver/ToolChains/Linux.h
===
--- lib/Driver/ToolChains/Linux.h
+++ lib/Driver/ToolChains/Linux.h
@@ -40,6 +40,7 @@
void addProfileRTLibs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
virtual std::string computeSysRoot() const;
+ virtual std::string computeIncludeSysRoot() const;
virtual std::string getDynamicLinker(const llvm::opt::ArgList &Args) const;
@@ -48,6 +49,7 @@
protected:
Tool *buildAssembler() const override;
Tool *buildLinker() const override;
+ std::string defaultSysRoot() const;
};
} // end namespace toolchains
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -380,10 +380,7 @@
return new tools::gnutools::Assembler(*this);
}
-std::string Linux::computeSysRoot() const {
- if (!getDriver().SysRoot.empty())
-return getDriver().SysRoot;
-
+std::string Linux::defaultSysRoot() const {
if (!GCCInstallation.isValid() || !tools::isMipsArch(getTriple().getArch()))
return std::string();
@@ -410,6 +407,20 @@
return std::string();
}
+std::string Linux::computeSysRoot() const {
+ if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+ return defaultSysRoot();
+}
+
+std::string Linux::computeIncludeSysRoot() const {
+ if (!getDriver().IncludeSysRoot.empty())
+return getDriver().IncludeSysRoot;
+
+ return computeSysRoot();
+}
+
std::string Linux::getDynamicLinker(const ArgList &Args) const {
const llvm::Triple::ArchType Arch = getArch();
const llvm::Triple &Triple = getTriple();
@@ -541,7 +552,7 @@
void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
const Driver &D = getDriver();
- std::string SysRoot = computeSysRoot();
+ std::string SysRoot = computeIncludeSysRoot();
if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
return;
@@ -732,8 +743,8 @@
// If this is a development, non-installed, clang, libcxx will
// not be found at ../include/c++ but it likely to be found at
// one of the following two locations:
- DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/local/include/c++"),
- DetectLibcxxIncludePath(getDriver().SysRoot + "/usr/include/c++") };
+ DetectLibcxxIncludePath(getDriver().IncludeSysRoot + "/usr/local/include/c++"),
+ DetectLibcxxIncludePath(getDriver().IncludeSysRoot + "/usr/include/c++") };
for (const auto &IncludePath : LibCXXIncludePathCandidates) {
if (IncludePath.empty() || !getVFS().exists(IncludePath))
continue;
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -88,7 +88,8 @@
: Opts(createDriverOptTable()), Diags(Diags), VFS(std::move(VFS)),
Mode(GCCMode), SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone),
LTOMode(LTOK_None), ClangExecutable(ClangExecutable),
- SysRoot(DEFAULT_SYSROOT), UseStdLib(true),
+ SysRoot(DEFAULT_SYSROOT), IncludeSysRoot(DEFAULT_SYSROOT),
+ UseStdLib(true),
DriverTitle("clang LLVM compiler"), CCPrintOptionsFilename(nullptr),
CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr),
CCCPrintBindings(false), CCPrintHe