[clang] [clang][AIX] set OpenMP include path (PR #88545)
Jake Egan via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 12 11:03:46 PDT 2024
https://github.com/jakeegan updated https://github.com/llvm/llvm-project/pull/88545
>From 4be38409fa322765c21a94759a78a23700e1a54d Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Fri, 12 Apr 2024 11:36:25 -0400
Subject: [PATCH 1/2] [clang][AIX] set OpenMP include path
---
clang/lib/Driver/ToolChains/AIX.cpp | 28 +++++++++++++++++++++
clang/lib/Driver/ToolChains/AIX.h | 2 ++
clang/test/Driver/aix-toolchain-include.cpp | 20 ++++++++++++++-
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index 3f10888596a29a..f1ad65884dca26 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -362,6 +362,29 @@ AIX::GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const {
return "/";
}
+void AIX::AddOpenMPIncludeArgs(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
+ // Add OpenMP include paths if -fopenmp is specified.
+ if (DriverArgs.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
+ options::OPT_fno_openmp, false)) {
+ SmallString<128> PathOpenMP;
+ switch (getDriver().getOpenMPRuntime(DriverArgs)) {
+ case Driver::OMPRT_OMP:
+ PathOpenMP = GetHeaderSysroot(DriverArgs);
+ llvm::sys::path::append(PathOpenMP, "opt/IBM/openxlCSDK", "include", "openmp");
+ addSystemInclude(DriverArgs, CC1Args, PathOpenMP.str());
+ break;
+ case Driver::OMPRT_IOMP5:
+ LLVM_FALLTHROUGH;
+ case Driver::OMPRT_GOMP:
+ LLVM_FALLTHROUGH;
+ case Driver::OMPRT_Unknown:
+ // Unknown / unsupported include paths.
+ break;
+ }
+ }
+}
+
void AIX::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
// Return if -nostdinc is specified as a driver option.
@@ -380,6 +403,11 @@ void AIX::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
addSystemInclude(DriverArgs, CC1Args, path::parent_path(P.str()));
}
+ // Add the include directory containing omp.h. This needs to be before
+ // adding the system include directory because other compilers put their
+ // omp.h in /usr/include.
+ AddOpenMPIncludeArgs(DriverArgs, CC1Args);
+
// Return if -nostdlibinc is specified as a driver option.
if (DriverArgs.hasArg(options::OPT_nostdlibinc))
return;
diff --git a/clang/lib/Driver/ToolChains/AIX.h b/clang/lib/Driver/ToolChains/AIX.h
index 755d87e07ec500..8f130f6b54547c 100644
--- a/clang/lib/Driver/ToolChains/AIX.h
+++ b/clang/lib/Driver/ToolChains/AIX.h
@@ -105,6 +105,8 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain {
private:
llvm::StringRef GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const;
bool ParseInlineAsmUsingAsmParser;
+ void AddOpenMPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const;
};
} // end namespace toolchains
diff --git a/clang/test/Driver/aix-toolchain-include.cpp b/clang/test/Driver/aix-toolchain-include.cpp
index fbe5fb8cb86131..31dc4fa9eb6a19 100644
--- a/clang/test/Driver/aix-toolchain-include.cpp
+++ b/clang/test/Driver/aix-toolchain-include.cpp
@@ -5,24 +5,28 @@
// RUN: --target=powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefixes=CHECK-INTERNAL-INCLUDE,CHECK-INTERNAL-INCLUDE-CXX %s
// RUN: %clangxx -### %s 2>&1 \
// RUN: --target=powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefixes=CHECK-INTERNAL-INCLUDE,CHECK-INTERNAL-INCLUDE-CXX %s
// RUN: %clang -### -xc %s 2>&1 \
// RUN: --target=powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
// RUN: %clang -### -xc %s 2>&1 \
// RUN: --target=powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
// CHECK-INTERNAL-INCLUDE: "-cc1"
@@ -31,6 +35,7 @@
// CHECK-INTERNAL-INCLUDE-CXX: "-internal-isystem" "[[SYSROOT]]{{(/|\\\\)}}opt{{(/|\\\\)}}IBM{{(/|\\\\)}}openxlCSDK{{(/|\\\\)}}include{{(/|\\\\)}}c++{{(/|\\\\)}}v1"
// CHECK-INTERNAL-INCLUDE-CXX: "-D__LIBC_NO_CPP_MATH_OVERLOADS__"
// CHECK-INTERNAL-INCLUDE: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// CHECK-INTERNAL-INCLUDE: "-internal-isystem" "[[SYSROOT]]{{(/|\\\\)}}opt{{(/|\\\\)}}IBM{{(/|\\\\)}}openxlCSDK{{(/|\\\\)}}include{{(/|\\\\)}}openmp"
// CHECK-INTERNAL-INCLUDE: "-internal-isystem" "[[SYSROOT]]/usr/include"
// Check powerpc-ibm-aix, 32-bit/64-bit. -nostdinc option.
@@ -73,6 +78,7 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdlibinc \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
// RUN: %clangxx -### %s 2>&1 \
@@ -80,6 +86,7 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdlibinc \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
// RUN: %clang -### -xc %s 2>&1 \
@@ -87,6 +94,7 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdlibinc \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
// RUN: %clang -### -xc %s 2>&1 \
@@ -94,15 +102,17 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdlibinc \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
// CHECK-NOSTDLIBINC-INCLUDE: "-cc1"
// CHECK-NOSTDLIBINC-INCLUDE: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK-NOSTDLIBINC-INCLUDE: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-NOSTDLIBINC-INCLUDE: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// CHECK-NOSTDLIBINC-INCLUDE: "-internal-isystem" "[[SYSROOT]]{{(/|\\\\)}}opt{{(/|\\\\)}}IBM{{(/|\\\\)}}openxlCSDK{{(/|\\\\)}}include{{(/|\\\\)}}openmp"
// CHECK-NOSTDLIBINC-INCLUDE-NOT: "-internal-isystem" "[[SYSROOT]]{{(/|\\\\)}}opt{{(/|\\\\)}}IBM{{(/|\\\\)}}openxlCSDK{{(/|\\\\)}}include{{(/|\\\\)}}c++{{(/|\\\\)}}v1"
// CHECK-NOSTDLIBINC-INCLUDE-NOT: "-D__LIBC_NO_CPP_MATH_OVERLOADS__"
-// CHECK-NOSTDLIBINC-INCLUDE-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include"
+// CHECK-NOSTDLIBINC-INCLUDE-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include"
// Check powerpc-ibm-aix, 32-bit/64-bit. -nobuiltininc option.
// RUN: %clangxx -### %s 2>&1 \
@@ -110,6 +120,7 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nobuiltininc \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefixes=CHECK-NOBUILTININC-INCLUDE,CHECK-NOBUILTININC-INCLUDE-CXX %s
// RUN: %clangxx -### %s 2>&1 \
@@ -117,6 +128,7 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nobuiltininc \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefixes=CHECK-NOBUILTININC-INCLUDE,CHECK-NOBUILTININC-INCLUDE-CXX %s
// RUN: %clang -### -xc %s 2>&1 \
@@ -124,6 +136,7 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nobuiltininc \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
// RUN: %clang -### -xc %s 2>&1 \
@@ -131,6 +144,7 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nobuiltininc \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
// CHECK-NOBUILTININC-INCLUDE: "-cc1"
@@ -139,6 +153,7 @@
// CHECK-NOBUILTININC-INCLUDE-NOT: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
// CHECK-NOBUILTININC-INCLUDE-CXX: "-internal-isystem" "[[SYSROOT]]{{(/|\\\\)}}opt{{(/|\\\\)}}IBM{{(/|\\\\)}}openxlCSDK{{(/|\\\\)}}include{{(/|\\\\)}}c++{{(/|\\\\)}}v1"
// CHECK-NOBUILTININC-INCLUDE-CXX: "-D__LIBC_NO_CPP_MATH_OVERLOADS__"
+// CHECK-NOBUILTININC-INCLUDE: "-internal-isystem" "[[SYSROOT]]{{(/|\\\\)}}opt{{(/|\\\\)}}IBM{{(/|\\\\)}}openxlCSDK{{(/|\\\\)}}include{{(/|\\\\)}}openmp"
// CHECK-NOBUILTININC-INCLUDE: "-internal-isystem" "[[SYSROOT]]/usr/include"
// Check powerpc-ibm-aix, 32-bit/64-bit. -nostdinc++ option.
@@ -147,6 +162,7 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdinc++ \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDINCXX-INCLUDE %s
// RUN: %clangxx -### %s 2>&1 \
@@ -154,6 +170,7 @@
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdinc++ \
+// RUN: -fopenmp \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDINCXX-INCLUDE %s
// CHECK-NOSTDINCXX-INCLUDE: "-cc1"
@@ -162,6 +179,7 @@
// CHECK-NOSTDINCXX-INCLUDE: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
// CHECK-NOSTDINCXX-INCLUDE-NOT: "-internal-isystem" "[[SYSROOT]]{{(/|\\\\)}}opt{{(/|\\\\)}}IBM{{(/|\\\\)}}openxlCSDK{{(/|\\\\)}}include{{(/|\\\\)}}c++{{(/|\\\\)}}v1"
// CHECK-NOSTDINCXX-INCLUDE-NOT: "-D__LIBC_NO_CPP_MATH_OVERLOADS__"
+// CHECK-NOSTDINCXX-INCLUDE: "-internal-isystem" "[[SYSROOT]]{{(/|\\\\)}}opt{{(/|\\\\)}}IBM{{(/|\\\\)}}openxlCSDK{{(/|\\\\)}}include{{(/|\\\\)}}openmp"
// CHECK-NOSTDINCXX-INCLUDE: "-internal-isystem" "[[SYSROOT]]/usr/include"
// Check powerpc-ibm-aix, 32-bit. -stdlib=libstdc++ invokes fatal error.
>From b3a46225baf51fd799e12af9850a45b54423ef23 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Fri, 12 Apr 2024 14:03:25 -0400
Subject: [PATCH 2/2] Apply clang-format changes
---
clang/lib/Driver/ToolChains/AIX.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index f1ad65884dca26..c1b350893b3744 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -366,12 +366,13 @@ void AIX::AddOpenMPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
// Add OpenMP include paths if -fopenmp is specified.
if (DriverArgs.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
- options::OPT_fno_openmp, false)) {
+ options::OPT_fno_openmp, false)) {
SmallString<128> PathOpenMP;
switch (getDriver().getOpenMPRuntime(DriverArgs)) {
case Driver::OMPRT_OMP:
PathOpenMP = GetHeaderSysroot(DriverArgs);
- llvm::sys::path::append(PathOpenMP, "opt/IBM/openxlCSDK", "include", "openmp");
+ llvm::sys::path::append(PathOpenMP, "opt/IBM/openxlCSDK", "include",
+ "openmp");
addSystemInclude(DriverArgs, CC1Args, PathOpenMP.str());
break;
case Driver::OMPRT_IOMP5:
More information about the cfe-commits
mailing list