]> git.ipfire.org Git - thirdparty/gcc.git/commit
OpenMP: Fix mapping of zero-sized arrays with non-literal size: map(var[:n]), n = 0 devel/omp/gcc-14
authorTobias Burnus <tburnus@baylibre.com>
Wed, 14 May 2025 18:06:49 +0000 (20:06 +0200)
committerTobias Burnus <tburnus@baylibre.com>
Wed, 14 May 2025 18:08:20 +0000 (20:08 +0200)
commita1c4b92e57874d549b3bc6bb776c7c16e9ada14a
tree9428681e9dbd952b66af3cd875e81fb8d82a3405
parent9a06e4d6a117497c2536bf89bb6c7536289e44bb
OpenMP: Fix mapping of zero-sized arrays with non-literal size: map(var[:n]), n = 0

For map(ptr[:0]), the used map kind is GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
and it is permitted that 'ptr' does not exist. 'ptr' is set to the device
pointee if it exists or to the host value otherwise.

For map(ptr[:3]), the variable is first mapped and then ptr is updated to point
to the just-mapped device data; the attachment uses GOMP_MAP_ATTACH.

For map(ptr[:n]), generates always a GOMP_MAP_ATTACH, but when n == 0, it
was failing with:
   "pointer target not mapped for attach"

The solution is not to fail but first to check whether it was mapped before.
It turned out that for the mapping part, GCC adds a run-time check whether
n == 0 - and uses GOMP_MAP_ZERO_LEN_ARRAY_SECTION for the mapping.
Thus, we just have to check whether there such a mapping for the address
for which the GOMP_MAP_ATTACH. was requested. And, if there was, the
error diagnostic can be skipped.

Unsurprisingly, this issue occurs in real-world code; it was detected in
a code that distributes work via MPI and for some processes, some bounds
ended up to be zero.

libgomp/ChangeLog:

* target.c (gomp_attach_pointer): Return bool; accept additional
bool to optionally silence the fatal pointee-not-found error.
(gomp_map_vars_internal): If the pointee could not be found,
check whether it was mapped as GOMP_MAP_ZERO_LEN_ARRAY_SECTION.
* libgomp.h (gomp_attach_pointer): Update prototype.
* oacc-mem.c (acc_attach_async, goacc_enter_data_internal): Update
calls.
* testsuite/libgomp.c/target-map-zero-sized.c: New test.
* testsuite/libgomp.c/target-map-zero-sized-2.c: New test.
* testsuite/libgomp.c/target-map-zero-sized-3.c: New test.

(cherry picked from commit 814e29e390b1e9253f9a38e0d84f5ebe5de0c13e)
libgomp/ChangeLog.omp
libgomp/libgomp.h
libgomp/oacc-mem.c
libgomp/target.c
libgomp/testsuite/libgomp.c/target-map-zero-sized-2.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/target-map-zero-sized-3.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c/target-map-zero-sized.c [new file with mode: 0644]