OMP: zero-length array sections

Jakub Jelinek jakub@redhat.com
Wed Jul 8 10:35:27 GMT 2020


On Wed, Jul 08, 2020 at 12:21:57PM +0200, Thomas Schwinge wrote:
> Andrew and I are currently trying to sort out zero-length array sections
> behavior in the OpenACC context.  From that fell out a testcase that I
> created to learn/verify (some of?) the OpenMP behavior.  OK to push?
> 
> 
> Oh, and any thought on this:
> 
>     int dev = omp_get_default_device();
>     bool shared_mem = false;
>     #pragma omp target map(alloc:shared_mem)
>     shared_mem = true;
>     #if 1 //TODO
>     /* 'omp_target_is_present' (and a few others) have behavior different from
>        most others, where 'devicep == NULL' is handled the same as 'device_num ==
>        GOMP_DEVICE_HOST_FALLBACK'.  Is that difference intentional?  */
>     /* Given that GCC doesn't support shared-memory offload devices, we fake the
>        expected thing as follows.  */
>     if (shared_mem)
>       dev = omp_get_initial_device(); // GOMP_DEVICE_HOST_FALLBACK
>     #endif

The difference is in quite unclear cases, where the device is either not
valid (outside of range) or the device used to be valid, but has been
unloaded already.
I don't remember why have I done it that way, we could as well treat also
the device == NULL cases as fallback, but any expectations how it will
behave in those cases are wrong IMHO.

>   int *a = malloc(n * sizeof *a);
>   assert(a);

I'd probably just return 0; from the test instead if a is NULL, that is not
something invalid.

Otherwise LGTM.

	Jakub



More information about the Gcc-patches mailing list