gcc/libgomp
Tobias Burnus a1c4b92e57 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 814e29e390)
2025-05-14 20:08:20 +02:00
..
config GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO Object Destruction API [PR119853, PR119854] 2025-04-25 18:55:33 +02:00
plugin libgomp/plugin/plugin-nvptx.c: Fix device used for stream creation 2025-03-24 19:59:36 +01:00
testsuite OpenMP: Fix mapping of zero-sized arrays with non-literal size: map(var[:n]), n = 0 2025-05-14 20:08:20 +02:00
.gitattributes libgomp: Fixes + cleanup for OpenACC's Fortran module + openacc_lib.h 2020-02-19 09:13:44 +01:00
ChangeLog Fortran: Add OpenMP 'interop' directive parsing support 2025-01-23 22:26:57 +01:00
ChangeLog.graphite
ChangeLog.omp OpenMP: Fix mapping of zero-sized arrays with non-literal size: map(var[:n]), n = 0 2025-05-14 20:08:20 +02:00
Makefile.am GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO Object Destruction API [PR119853, PR119854] 2025-04-25 18:55:33 +02:00
Makefile.in GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO Object Destruction API [PR119853, PR119854] 2025-04-25 18:55:33 +02:00
acc_prof.h Update copyright years. 2024-01-03 12:19:35 +01:00
acinclude.m4 libgomp: fix typo in mold linker detection 2022-06-28 10:35:32 +02:00
aclocal.m4 libgomp: Regenerate configure files with automake 1.15.1 2020-10-02 12:08:47 +02:00
affinity-fmt.c Update copyright years. 2024-01-03 12:19:35 +01:00
affinity.c Update copyright years. 2024-01-03 12:19:35 +01:00
alloc.c Update copyright years. 2024-01-03 12:19:35 +01:00
allocator.c libgomp, openmp: Add ompx_pinned_mem_alloc 2024-06-27 12:57:41 +02:00
atomic.c Update copyright years. 2024-01-03 12:19:35 +01:00
barrier.c Update copyright years. 2024-01-03 12:19:35 +01:00
basic-allocator.c Update copyright years. 2024-01-03 12:19:35 +01:00
config.h.in Refactor '-ldl' handling for libgomp proper and plugins 2022-05-12 15:11:30 +02:00
configure libgomp: Fix up FLOCK fallback handling [PR113192] 2024-01-10 13:32:02 +01:00
configure.ac libgomp: Fix up FLOCK fallback handling [PR113192] 2024-01-10 13:32:02 +01:00
configure.tgt libgomp: Define config_path for hppa*-*-linux* 2024-02-11 20:23:14 +00:00
critical.c Update copyright years. 2024-01-03 12:19:35 +01:00
env.c libgomp: parallel reverse offload 2024-06-27 17:58:13 +02:00
error.c Update copyright years. 2024-01-03 12:19:35 +01:00
fortran.c OpenMP: Fix omp_get_device_from_uid, minor cleanup 2025-01-23 22:37:06 +01:00
hashtab.h Update copyright years. 2024-01-03 12:19:35 +01:00
icv-device.c OpenMP: 'interop' construct - add ME support + target-independent libgomp 2025-03-22 00:28:19 +01:00
icv.c Update copyright years. 2024-01-03 12:19:35 +01:00
iter.c Update copyright years. 2024-01-03 12:19:35 +01:00
iter_ull.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgomp-plugin.c libgomp: parallel reverse offload 2024-06-27 17:58:13 +02:00
libgomp-plugin.h OpenMP: 'interop' construct - add ME support + target-independent libgomp 2025-03-22 00:28:19 +01:00
libgomp.h OpenMP: Fix mapping of zero-sized arrays with non-literal size: map(var[:n]), n = 0 2025-05-14 20:08:20 +02:00
libgomp.map OpenMP: 'interop' construct - add ME support + target-independent libgomp 2025-03-22 00:28:19 +01:00
libgomp.spec.in
libgomp.texi OpenMP: need_device_ptr and need_device_addr support for adjust_args 2025-04-30 17:46:31 +00:00
libgomp_f.h.in Update copyright years. 2024-01-03 12:19:35 +01:00
libgomp_g.h OpenMP: 'interop' construct - add ME support + target-independent libgomp 2025-03-22 00:28:19 +01:00
lock.c Update copyright years. 2024-01-03 12:19:35 +01:00
loop.c Update copyright years. 2024-01-03 12:19:35 +01:00
loop_ull.c Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-async.c Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-cuda.c Tweak error return value for acc_set_cuda_stream. 2024-06-27 12:52:46 +02:00
oacc-host.c OpenMP: Fix omp_get_device_from_uid, minor cleanup 2025-01-23 22:37:06 +01:00
oacc-init.c Add changes to profiling interface from OG8 branch 2024-06-27 12:52:48 +02:00
oacc-int.h OpenACC: Pass pre-allocated 'ptrblock' to 'goacc_noncontig_array_create_ptrblock' [PR76739] 2024-06-27 12:57:44 +02:00
oacc-mem.c OpenMP: Fix mapping of zero-sized arrays with non-literal size: map(var[:n]), n = 0 2025-05-14 20:08:20 +02:00
oacc-parallel.c OpenACC: Pass pre-allocated 'ptrblock' to 'goacc_noncontig_array_create_ptrblock' [PR76739] 2024-06-27 12:57:44 +02:00
oacc-plugin.c Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-plugin.h Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-profiling-acc_register_library.c Add changes to profiling interface from OG8 branch 2024-06-27 12:52:48 +02:00
oacc-profiling.c Add changes to profiling interface from OG8 branch 2024-06-27 12:52:48 +02:00
oacc-target.c GCN libgomp port 2019-11-13 12:38:04 +00:00
omp.h.in OpenMP: Add get_device_from_uid/omp_get_uid_from_device routines 2025-01-23 22:35:31 +01:00
omp_lib.f90.in OpenMP: Fix omp_get_device_from_uid, minor cleanup 2025-01-23 22:37:06 +01:00
omp_lib.h.in OpenMP: Fix omp_get_device_from_uid, minor cleanup 2025-01-23 22:37:06 +01:00
openacc.f90 OpenACC 2.7: adjust 2.6 references to 2.7 2025-04-11 13:51:55 +00:00
openacc.h Update copyright years. 2024-01-03 12:19:35 +01:00
openacc_lib.h OpenACC 2.7: adjust 2.6 references to 2.7 2025-04-11 13:51:55 +00:00
ordered.c Update copyright years. 2024-01-03 12:19:35 +01:00
parallel.c Update copyright years. 2024-01-03 12:19:35 +01:00
priority_queue.c Update copyright years. 2024-01-03 12:19:35 +01:00
priority_queue.h Fix up duplicated words mostly in comments, part 1 2024-04-02 13:39:11 +02:00
scope.c Update copyright years. 2024-01-03 12:19:35 +01:00
sections.c Update copyright years. 2024-01-03 12:19:35 +01:00
secure_getenv.h Update copyright years. 2024-01-03 12:19:35 +01:00
selector.c libgomp: runtime support for target_device selector 2024-06-27 17:58:14 +02:00
single.c Update copyright years. 2024-01-03 12:19:35 +01:00
splay-tree.c Update copyright years. 2024-01-03 12:19:35 +01:00
splay-tree.h Update copyright years. 2024-01-03 12:19:35 +01:00
target-cxa-dso-dtor.c GCN, nvptx offloading: Host/device compatibility: Itanium C++ ABI, DSO Object Destruction API [PR119853, PR119854] 2025-04-25 18:55:33 +02:00
target-indirect.c Update copyright years. 2024-01-03 12:19:35 +01:00
target.c OpenMP: Fix mapping of zero-sized arrays with non-literal size: map(var[:n]), n = 0 2025-05-14 20:08:20 +02:00
task.c Update copyright years. 2024-01-03 12:19:35 +01:00
taskloop.c Update copyright years. 2024-01-03 12:19:35 +01:00
team.c Update copyright years. 2024-01-03 12:19:35 +01:00
teams.c Update copyright years. 2024-01-03 12:19:35 +01:00
usmpin-allocator.c libgomp: fine-grained pinned memory allocator 2024-06-27 12:57:41 +02:00
work.c Update copyright years. 2024-01-03 12:19:35 +01:00