This is an archive of the discontinued LLVM Phabricator instance.

[openmp] [test] Fix data structure mismatches for tests that define kmp_depend_info
ClosedPublic

Authored by mstorsjo on Nov 9 2022, 2:28 PM.

Details

Summary

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.

Diff Detail

Event Timeline

mstorsjo created this revision.Nov 9 2022, 2:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2022, 2:28 PM
mstorsjo requested review of this revision.Nov 9 2022, 2:28 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: sstefan1. · View Herald Transcript

FWIW, I forgot to add in the commit description, that this fixes tests that fail on Windows on aarch64 (built with Clang), while they did succeed on x86_64.

FWIW, I forgot to add in the commit description, that this fixes tests that fail on Windows on aarch64 (built with Clang), while they did succeed on x86_64.

Actually, I think the error that this fixes does show up on x86_64 too.

mstorsjo added a subscriber: DavidSpickett.

Adding @DavidSpickett here too, since he's been very helpful with review elsewhere. But feel free to skip this one if you feel it's out of scope for you.

There's basically two essential changes here, plus one optional:

  • Use the right sized intptr_t instead of long for passing pointers in integers on Windows
  • Zero-initialize a struct before we set individual flags in a bitfield (the library reads the bitfield as a complete integer instead of reading individual bits)

Optional:

  • The test manually defines libomp internal data structures and passes such structs to the library. The struct definition in the test code differs vaguely from the real one used in libomp. Synchronize this to use the exact same definition as internally. This doesn't affect whether the tests pass or fail currently.
jlpeyton added inline comments.Nov 28 2022, 6:27 AM
openmp/runtime/test/tasking/bug_nested_proxy_task.c
23–29

Can we #include stdint.h above and then use

typedef intptr_t kmp_intptr_t;
typedef int32_t kmp_int32;
typedef uint8_t kmp_uint8;
openmp/runtime/test/tasking/bug_proxy_task_dep_waiting.c
20–26

Same as previous comment.

mstorsjo added inline comments.Nov 28 2022, 6:33 AM
openmp/runtime/test/tasking/bug_nested_proxy_task.c
23–29

That works for me too. But can we do it in two separate patches - first this, and then changing to using stdint.h? In case the stdint.h change breaks something unexpected in a weird environment and the change needs to be reverted, we'd still have the tests fixed on Win64.

jlpeyton accepted this revision.Nov 28 2022, 6:35 AM

Sounds good to me.

This revision is now accepted and ready to land.Nov 28 2022, 6:35 AM
natgla added inline comments.Nov 28 2022, 9:30 AM
openmp/runtime/test/tasking/bug_nested_proxy_task.c
56

sorry for being late here. if the bit field is defined as unsigned, the set of bit fields will take at least "unsigned" space (4 bytes). Judging by union with flag: do you want to define all these as kmp_uint8? (same below)

mstorsjo added inline comments.Nov 28 2022, 9:36 AM
openmp/runtime/test/tasking/bug_nested_proxy_task.c
56

No, here, I want exactly this - and your comment is even more reason for it.

Here, we’re redefining an libomp internal struct, and exactly for rains like this, we really should have an exactly matching definition to the one in kmp.h in the source tree.

You’re right that we probably should change it like you’re suggesting - but then we should change kmp.h too, in sync with this.

natgla added inline comments.Nov 28 2022, 9:53 AM
openmp/runtime/test/tasking/bug_nested_proxy_task.c
56

would you mind adding a comment on kmp_depend_info explaining that it's exact copy of kmp_depend_info from kmp.h? (or if there are other structs here, more general comment?)

mstorsjo added inline comments.Nov 28 2022, 12:34 PM
openmp/runtime/test/tasking/bug_nested_proxy_task.c
56

Sure, I can do that.

In practice, I have no idea how this is meant to be used in practice - is this something that regular users of OpenMP are supposed to do, or is it just a intrusive test? But in any case, this brings the testsuite to passing in more cases.

natgla added inline comments.Nov 28 2022, 1:05 PM
openmp/runtime/test/tasking/bug_nested_proxy_task.c
56

looks like a unit test for runtime to me. It's emulating what compiler would generate (see comment at the top of the test)