Skip to content

Commit a91b9bd

Browse files
vadikp-inteltstellar
authored andcommitted
[OpenMP] fix endianness dependent definitions in OMP headers for MSVC (llvm#84540)
MSVC does not define __BYTE_ORDER__ making the check for BigEndian erroneously evaluate to true and breaking the struct definitions in MSVC compiled builds correspondingly. The fix adds an additional check for whether __BYTE_ORDER__ is defined by the compiler to fix these. --------- Co-authored-by: Vadim Paretsky <b-vadipa@microsoft.com> (cherry picked from commit 110141b)
1 parent 7cb6753 commit a91b9bd

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

openmp/runtime/src/kmp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2506,7 +2506,7 @@ typedef struct kmp_depend_info {
25062506
union {
25072507
kmp_uint8 flag; // flag as an unsigned char
25082508
struct { // flag as a set of 8 bits
2509-
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
2509+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
25102510
/* Same fields as in the #else branch, but in reverse order */
25112511
unsigned all : 1;
25122512
unsigned unused : 3;
@@ -2671,7 +2671,7 @@ typedef struct kmp_task_stack {
26712671
#endif // BUILD_TIED_TASK_STACK
26722672

26732673
typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
2674-
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
2674+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
26752675
/* Same fields as in the #else branch, but in reverse order */
26762676
#if OMPX_TASKGRAPH
26772677
unsigned reserved31 : 6;

openmp/runtime/src/kmp_lock.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ extern void __kmp_validate_locks(void);
120120

121121
struct kmp_base_tas_lock {
122122
// KMP_LOCK_FREE(tas) => unlocked; locked: (gtid+1) of owning thread
123-
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __LP64__
123+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) && \
124+
__LP64__
124125
// Flip the ordering of the high and low 32-bit member to be consistent
125126
// with the memory layout of the address in 64-bit big-endian.
126127
kmp_int32 depth_locked; // depth locked, for nested locks only

openmp/runtime/test/tasking/bug_nested_proxy_task.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef struct kmp_depend_info {
5050
union {
5151
kmp_uint8 flag; // flag as an unsigned char
5252
struct { // flag as a set of 8 bits
53-
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
53+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
5454
unsigned all : 1;
5555
unsigned unused : 3;
5656
unsigned set : 1;

openmp/runtime/test/tasking/bug_proxy_task_dep_waiting.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ typedef struct kmp_depend_info {
4747
union {
4848
kmp_uint8 flag; // flag as an unsigned char
4949
struct { // flag as a set of 8 bits
50-
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
50+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
5151
unsigned all : 1;
5252
unsigned unused : 3;
5353
unsigned set : 1;

openmp/runtime/test/tasking/hidden_helper_task/common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef struct kmp_depend_info {
1717
union {
1818
unsigned char flag;
1919
struct {
20-
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
20+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2121
unsigned all : 1;
2222
unsigned unused : 3;
2323
unsigned set : 1;

0 commit comments

Comments
 (0)