Skip to content

Commit b32c6d1

Browse files
authored
[OpenMP] Fix KMP_OS_AIX handling (#138499)
When building `openmp` on Linux/sparc64, I get ``` In file included fromopenmp/runtime/src/kmp_utility.cpp:16: openmp/runtime/src/kmp_wrapper_getpid.h:47:2: warning: No gettid found, use getpid instead [-W#warnings] 47 | #warning No gettid found, use getpid instead | ^ ``` This is highly confusing since `<sys/syscall.h>` **does** define `SYS_gettid` and the header is supposed to be included: ``` #if !defined(KMP_OS_AIX) && !defined(KMP_OS_HAIKU) #include <sys/syscall.h> #endif ``` However, this actually is **not** the case for two reasons: - `KMP_OS_HAIKU` is always defined, either as 1 on Haiku or as 0 otherwise. - `KMP_OS_AIX` is even worse: it is only defined as 1 on on AIX, but undefined otherwise. All those `KMP_OS_*` macros are supposed to always be defined as 1/0 as appropriate, and to be checked with `#if`, not `#ifdef`. AIX is violating this, causing the problem above. Other targets probably get `<sys/syscall.h>` indirectly otherwise, but Linux/sparc64 does not. This patch fixes this by also defining `KMP_OS_AIX` as 0 on other OSes and changing the checks to `#if` as necessary. Tested on `sparc64-unknown-linux-gnu`, `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and `x86_64-pc-linux-gnu`.
1 parent 4fb7d19 commit b32c6d1

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

openmp/runtime/src/kmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ class KMPAffinity {
821821
typedef KMPAffinity::Mask kmp_affin_mask_t;
822822
extern KMPAffinity *__kmp_affinity_dispatch;
823823

824-
#ifndef KMP_OS_AIX
824+
#if !KMP_OS_AIX
825825
class kmp_affinity_raii_t {
826826
kmp_affin_mask_t *mask;
827827
bool restored;

openmp/runtime/src/kmp_affinity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5468,7 +5468,7 @@ void __kmp_affinity_bind_init_mask(int gtid) {
54685468
__kmp_set_system_affinity(th->th.th_affin_mask, FALSE);
54695469
} else
54705470
#endif
5471-
#ifndef KMP_OS_AIX
5471+
#if !KMP_OS_AIX
54725472
// Do not set the full mask as the init mask on AIX.
54735473
__kmp_set_system_affinity(th->th.th_affin_mask, TRUE);
54745474
#endif

openmp/runtime/src/kmp_platform.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define KMP_OS_SOLARIS 0
2828
#define KMP_OS_WASI 0
2929
#define KMP_OS_EMSCRIPTEN 0
30+
#define KMP_OS_AIX 0
3031
#define KMP_OS_UNIX 0 /* disjunction of KMP_OS_LINUX, KMP_OS_DARWIN etc. */
3132

3233
#ifdef _WIN32
@@ -163,11 +164,11 @@
163164
#undef KMP_ARCH_PPC64_ELFv1
164165
#define KMP_ARCH_PPC64_ELFv1 1
165166
#endif
166-
#elif defined KMP_OS_AIX
167+
#elif KMP_OS_AIX
167168
#undef KMP_ARCH_PPC64_XCOFF
168169
#define KMP_ARCH_PPC64_XCOFF 1
169170
#endif
170-
#elif defined(__powerpc__) && defined(KMP_OS_AIX)
171+
#elif defined(__powerpc__) && KMP_OS_AIX
171172
#undef KMP_ARCH_PPC_XCOFF
172173
#define KMP_ARCH_PPC_XCOFF 1
173174
#undef KMP_ARCH_PPC

openmp/runtime/src/kmp_wrapper_getpid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard
1919
// headers.
20-
#if !defined(KMP_OS_AIX) && !defined(KMP_OS_HAIKU)
20+
#if !KMP_OS_AIX && !KMP_OS_HAIKU
2121
#include <sys/syscall.h>
2222
#endif
2323
#include <sys/types.h>

0 commit comments

Comments
 (0)