[clang] 1a2f482 - [Clang] Handle AIX Include management in the driver
David Tenty via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 7 08:15:13 PDT 2020
Author: Shuhong Liu
Date: 2020-07-07T11:15:06-04:00
New Revision: 1a2f4824cb2d472649e65f845510ac0e47ca98c1
URL: https://github.com/llvm/llvm-project/commit/1a2f4824cb2d472649e65f845510ac0e47ca98c1
DIFF: https://github.com/llvm/llvm-project/commit/1a2f4824cb2d472649e65f845510ac0e47ca98c1.diff
LOG: [Clang] Handle AIX Include management in the driver
Summary: Modify the AIX clang toolchain to include AIX dependencies in the search path
Reviewers: daltenty, stevewan, hubert.reinterpretcast
Reviewed By: daltenty, stevewan, hubert.reinterpretcast
Subscribers: ormris, hubert.reinterpretcast, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82677
Added:
clang/test/Driver/aix-toolchain-include.cpp
Modified:
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Driver/ToolChains/AIX.h
clang/lib/Frontend/InitHeaderSearch.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index 0194f452111a..ac5544eedb00 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -13,12 +13,15 @@
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
#include "llvm/Option/ArgList.h"
+#include "llvm/Support/Path.h"
using AIX = clang::driver::toolchains::AIX;
using namespace clang::driver;
using namespace clang::driver::tools;
+using namespace clang::driver::toolchains;
using namespace llvm::opt;
+using namespace llvm::sys;
void aix::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
@@ -163,6 +166,43 @@ AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
}
+// Returns the effective header sysroot path to use.
+// This comes from either -isysroot or --sysroot.
+llvm::StringRef
+AIX::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 AIX::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
+ // Return if -nostdinc is specified as a driver option.
+ if (DriverArgs.hasArg(options::OPT_nostdinc))
+ return;
+
+ llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
+ const Driver &D = getDriver();
+
+ // Add the Clang builtin headers (<resource>/include).
+ if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+ SmallString<128> P(D.ResourceDir);
+ path::append(P, "/include");
+ addSystemInclude(DriverArgs, CC1Args, P.str());
+ }
+
+ // Return if -nostdlibinc is specified as a driver option.
+ if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+ return;
+
+ // Add <sysroot>/usr/include.
+ SmallString<128> UP(Sysroot);
+ path::append(UP, "/usr/include");
+ addSystemInclude(DriverArgs, CC1Args, UP.str());
+}
+
auto AIX::buildAssembler() const -> Tool * { return new aix::Assembler(*this); }
auto AIX::buildLinker() const -> Tool * { return new aix::Linker(*this); }
diff --git a/clang/lib/Driver/ToolChains/AIX.h b/clang/lib/Driver/ToolChains/AIX.h
index 69b948bc0ea8..942bb3cceb8a 100644
--- a/clang/lib/Driver/ToolChains/AIX.h
+++ b/clang/lib/Driver/ToolChains/AIX.h
@@ -63,9 +63,16 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain {
bool isPIEDefault() const override { return false; }
bool isPICDefaultForced() const override { return true; }
+ void
+ AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
+
protected:
Tool *buildAssembler() const override;
Tool *buildLinker() const override;
+
+private:
+ llvm::StringRef GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const;
};
} // end namespace toolchains
diff --git a/clang/lib/Frontend/InitHeaderSearch.cpp b/clang/lib/Frontend/InitHeaderSearch.cpp
index 159cd47f7831..16f1f1670e8d 100644
--- a/clang/lib/Frontend/InitHeaderSearch.cpp
+++ b/clang/lib/Frontend/InitHeaderSearch.cpp
@@ -381,6 +381,7 @@ void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
case llvm::Triple::Linux:
case llvm::Triple::Hurd:
case llvm::Triple::Solaris:
+ case llvm::Triple::AIX:
llvm_unreachable("Include management is handled in the driver.");
break;
case llvm::Triple::Win32:
@@ -424,6 +425,7 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
case llvm::Triple::Hurd:
case llvm::Triple::Solaris:
case llvm::Triple::WASI:
+ case llvm::Triple::AIX:
return;
case llvm::Triple::Win32:
diff --git a/clang/test/Driver/aix-toolchain-include.cpp b/clang/test/Driver/aix-toolchain-include.cpp
new file mode 100644
index 000000000000..dc8b272936a4
--- /dev/null
+++ b/clang/test/Driver/aix-toolchain-include.cpp
@@ -0,0 +1,136 @@
+// Tests that the AIX toolchain adds system includes to its search path.
+
+// Check powerpc-ibm-aix, 32-bit/64-bit.
+// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
+
+// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc64-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
+
+// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
+
+// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc64-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
+
+// CHECK-INTERNAL-INCLUDE: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-INTERNAL-INCLUDE: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-INTERNAL-INCLUDE: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-INTERNAL-INCLUDE: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// CHECK-INTERNAL-INCLUDE: "-internal-isystem" "[[SYSROOT]]/usr/include"
+
+// Check powerpc-ibm-aix, 32-bit/64-bit. -nostdinc option.
+// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nostdinc \
+// RUN: | FileCheck -check-prefix=CHECK-NOSTDINC-INCLUDE %s
+
+// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc64-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nostdinc \
+// RUN: | FileCheck -check-prefix=CHECK-NOSTDINC-INCLUDE %s
+
+// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nostdinc \
+// RUN: | FileCheck -check-prefix=CHECK-NOSTDINC-INCLUDE %s
+
+// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc64-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nostdinc \
+// RUN: | FileCheck -check-prefix=CHECK-NOSTDINC-INCLUDE %s
+
+// CHECK-NOSTDINC-INCLUDE: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-NOSTDINC-INCLUDE: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-NOSTDINC-INCLUDE: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-NOSTDINC-INCLUDE-NOT: "-internal-isystem"
+
+// Check powerpc-ibm-aix, 32-bit/64-bit. -nostdlibinc option.
+// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nostdlibinc \
+// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
+
+// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc64-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nostdlibinc \
+// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
+
+// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nostdlibinc \
+// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
+
+// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc64-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nostdlibinc \
+// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
+
+// CHECK-NOSTDLIBINC-INCLUDE: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-NOSTDLIBINC-INCLUDE: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-NOSTDLIBINC-INCLUDE: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-NOSTDLIBINC-INCLUDE: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// CHECK-NOSTDLIBINC-INCLUDE-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include"
+
+// Check powerpc-ibm-aix, 32-bit/64-bit. -nobuiltininc option.
+// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nobuiltininc \
+// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
+
+// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc64-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nobuiltininc \
+// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
+
+// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nobuiltininc \
+// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
+
+// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
+// RUN: -target powerpc64-ibm-aix \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -nobuiltininc \
+// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
+
+// CHECK-NOBUILTININC-INCLUDE: {{.*}}clang{{.*}}" "-cc1"
+// CHECK-NOBUILTININC-INCLUDE: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-NOBUILTININC-INCLUDE: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-NOBUILTININC-INCLUDE-NOT: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// CHECK-NOBUILTININC-INCLUDE: "-internal-isystem" "[[SYSROOT]]/usr/include"
More information about the cfe-commits
mailing list