[Openmp-commits] [openmp] 4ed8fcc - [openmp] [test] Fix data structure mismatches for tests that define kmp_depend_info
Martin Storsjö via Openmp-commits
openmp-commits at lists.llvm.org
Mon Nov 28 12:40:51 PST 2022
Author: Martin Storsjö
Date: 2022-11-28T22:40:02+02:00
New Revision: 4ed8fcc59a699b3eb62c6a8929f4589dd3463776
URL: https://github.com/llvm/llvm-project/commit/4ed8fcc59a699b3eb62c6a8929f4589dd3463776
DIFF: https://github.com/llvm/llvm-project/commit/4ed8fcc59a699b3eb62c6a8929f4589dd3463776.diff
LOG: [openmp] [test] Fix data structure mismatches for tests that define kmp_depend_info
Use the correct data type for pointer sized integers on Windows;
"long" is always 32 bit, even on 64 bit Windows - don't use it
for the kmp_intptr_t type.
Provide the exact correct definition of the kmp_depend_info
struct - avoid the risk of mismatches (if a platform would pack
things slightly differently when things are declared differently).
Zero initialize the whole dep_info struct before filling it in;
if only setting the in/out bits, the rest of the unallocated bits
in the bitfield can have undefined values. Libomp reads the flags
in combined form as an kmp_uint8 by reading the flag field - thus,
the unused bits do need to be zeroed. (Alternatively, the flag field
could be set to zero before setting the individual bits in the
bitfield).
Use kmp_intptr_t instead of long for casting pointers to integers.
Differential Revision: https://reviews.llvm.org/D137748
Added:
Modified:
openmp/runtime/test/tasking/bug_nested_proxy_task.c
openmp/runtime/test/tasking/bug_proxy_task_dep_waiting.c
Removed:
################################################################################
diff --git a/openmp/runtime/test/tasking/bug_nested_proxy_task.c b/openmp/runtime/test/tasking/bug_nested_proxy_task.c
index 44e754bef0449..b3aa32f95e32a 100644
--- a/openmp/runtime/test/tasking/bug_nested_proxy_task.c
+++ b/openmp/runtime/test/tasking/bug_nested_proxy_task.c
@@ -20,11 +20,18 @@
*/
// Compiler-generated code (emulation)
+#ifdef _WIN64
+typedef long long kmp_intptr_t;
+#else
typedef long kmp_intptr_t;
+#endif
typedef int kmp_int32;
+typedef unsigned char kmp_uint8;
typedef char bool;
+// These structs need to match the implementation within libomp, in kmp.h.
+
typedef struct ident {
kmp_int32 reserved_1; /**< might be used in Fortran; see above */
kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags; KMP_IDENT_KMPC identifies this union member */
@@ -43,10 +50,17 @@ typedef struct ident {
typedef struct kmp_depend_info {
kmp_intptr_t base_addr;
size_t len;
- struct {
- bool in:1;
- bool out:1;
- } flags;
+ union {
+ kmp_uint8 flag; // flag as an unsigned char
+ struct { // flag as a set of 8 bits
+ unsigned in : 1;
+ unsigned out : 1;
+ unsigned mtx : 1;
+ unsigned set : 1;
+ unsigned unused : 3;
+ unsigned all : 1;
+ } flags;
+ };
} kmp_depend_info_t;
struct kmp_task;
@@ -105,8 +119,8 @@ int main()
my_sleep( 0.1 );
}
*/
- kmp_depend_info_t dep_info;
- dep_info.base_addr = (long) &dep;
+ kmp_depend_info_t dep_info = { 0 };
+ dep_info.base_addr = (kmp_intptr_t) &dep;
dep_info.len = sizeof(int);
// out = inout per spec and runtime expects this
dep_info.flags.in = 1;
diff --git a/openmp/runtime/test/tasking/bug_proxy_task_dep_waiting.c b/openmp/runtime/test/tasking/bug_proxy_task_dep_waiting.c
index 7737a0ef7c67c..112329a6a1170 100644
--- a/openmp/runtime/test/tasking/bug_proxy_task_dep_waiting.c
+++ b/openmp/runtime/test/tasking/bug_proxy_task_dep_waiting.c
@@ -17,11 +17,18 @@
*/
// Compiler-generated code (emulation)
+#ifdef _WIN64
+typedef long long kmp_intptr_t;
+#else
typedef long kmp_intptr_t;
+#endif
typedef int kmp_int32;
+typedef unsigned char kmp_uint8;
typedef char bool;
+// These structs need to match the implementation within libomp, in kmp.h.
+
typedef struct ident {
kmp_int32 reserved_1; /**< might be used in Fortran; see above */
kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags; KMP_IDENT_KMPC identifies this union member */
@@ -40,10 +47,17 @@ typedef struct ident {
typedef struct kmp_depend_info {
kmp_intptr_t base_addr;
size_t len;
- struct {
- bool in:1;
- bool out:1;
- } flags;
+ union {
+ kmp_uint8 flag; // flag as an unsigned char
+ struct { // flag as a set of 8 bits
+ unsigned in : 1;
+ unsigned out : 1;
+ unsigned mtx : 1;
+ unsigned set : 1;
+ unsigned unused : 3;
+ unsigned all : 1;
+ } flags;
+ };
} kmp_depend_info_t;
struct kmp_task;
@@ -100,8 +114,8 @@ int main()
my_sleep( 0.1 );
}
*/
- kmp_depend_info_t dep_info;
- dep_info.base_addr = (long) &dep;
+ kmp_depend_info_t dep_info = { 0 };
+ dep_info.base_addr = (kmp_intptr_t) &dep;
dep_info.len = sizeof(int);
// out = inout per spec and runtime expects this
dep_info.flags.in = 1;
More information about the Openmp-commits
mailing list