#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,
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); }
--- /dev/null
+// 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"