From a4d378186156b7d877bc69b87a5f2dab31fa302f Mon Sep 17 00:00:00 2001 From: Kwok Cheung Yeung Date: Wed, 30 Jan 2019 10:43:47 -0800 Subject: [PATCH] Allow NULL for update directives in OpenACC 2.6 A non-present passed-by-reference Fortran optional argument is represented by a null pointer. When passed to an update directive, it should be ignored as variable mappings are not created for null pointers. This should be safe as it is not possible to change a non-present argument into a present one (or vice-versa) in Fortran. libgomp/ * oacc-mem.c (update_dev_host): Return early if the host address is NULL. * testsuite/libgomp.oacc-c-c++-common/lib-43.c: Remove. * testsuite/libgomp.oacc-c-c++-common/lib-47.c: Likewise. Reviewed-by: Julian Brown Reviewed-by: Thomas Schwinge (cherry picked from openacc-gcc-9-branch commit b930a8a1ee826ca52081c7c0e88554b3091afb62) --- libgomp/ChangeLog.omp | 7 +++ libgomp/oacc-mem.c | 6 +++ .../libgomp.oacc-c-c++-common/lib-43.c | 51 ------------------- .../libgomp.oacc-c-c++-common/lib-47.c | 49 ------------------ 4 files changed, 13 insertions(+), 100 deletions(-) delete mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-43.c delete mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-47.c diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index f338eb1cf483..79baa0cfee10 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,10 @@ +2019-01-30 Kwok Cheung Yeung + + * oacc-mem.c (update_dev_host): Return early if the host address + is NULL. + * testsuite/libgomp.oacc-c-c++-common/lib-43.c: Remove. + * testsuite/libgomp.oacc-c-c++-common/lib-47.c: Likewise. + 2018-12-11 Julian Brown Chung-Lin Tang diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c index 2ff8d7f91474..b3b37771da20 100644 --- a/libgomp/oacc-mem.c +++ b/libgomp/oacc-mem.c @@ -692,6 +692,12 @@ update_dev_host (int is_dev, void *h, size_t s, int async) if (acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) return; + /* Fortran optional arguments that are non-present result in a + null host address here. This can safely be ignored as it is + not possible to 'update' a non-present optional argument. */ + if (h == NULL) + return; + gomp_mutex_lock (&acc_dev->lock); n = lookup_host (acc_dev, h, s); diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-43.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-43.c deleted file mode 100644 index 5db29124e9ec..000000000000 --- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-43.c +++ /dev/null @@ -1,51 +0,0 @@ -/* Exercise acc_update_device with a NULL data address on nvidia targets. */ - -/* { dg-do run { target openacc_nvidia_accel_selected } } */ - -#include -#include -#include - -int -main (int argc, char **argv) -{ - const int N = 256; - int i; - unsigned char *h; - void *d; - - h = (unsigned char *) malloc (N); - - for (i = 0; i < N; i++) - { - h[i] = i; - } - - d = acc_copyin (h, N); - if (!d) - abort (); - - for (i = 0; i < N; i++) - { - h[i] = 0xab; - } - - fprintf (stderr, "CheCKpOInT\n"); - acc_update_device (0, N); - - acc_copyout (h, N); - - for (i = 0; i < N; i++) - { - if (h[i] != 0xab) - abort (); - } - - free (h); - - return 0; -} - -/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */ -/* { dg-output "\\\[\[^\n\r]*,256\\\] is not mapped" } */ -/* { dg-shouldfail "" } */ diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-47.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-47.c deleted file mode 100644 index c2140429cb1e..000000000000 --- a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-47.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Exercise acc_update_self with a NULL data mapping on nvidia targets. */ - -/* { dg-do run { target openacc_nvidia_accel_selected } } */ - -#include -#include -#include -#include - -int -main (int argc, char **argv) -{ - const int N = 256; - int i; - unsigned char *h; - void *d; - - h = (unsigned char *) malloc (N); - - for (i = 0; i < N; i++) - { - h[i] = i; - } - - d = acc_copyin (h, N); - if (!d) - abort (); - - memset (&h[0], 0, N); - - fprintf (stderr, "CheCKpOInT\n"); - acc_update_self (0, N); - - for (i = 0; i < N; i++) - { - if (h[i] != i) - abort (); - } - - acc_delete (h, N); - - free (h); - - return 0; -} - -/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */ -/* { dg-output "\\\[\[^\n\r]*,256\\\] is not mapped" } */ -/* { dg-shouldfail "" } */ -- 2.47.2