From 67c259509c0ab6475a27e871afdf12434ac34d48 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Wed, 2 Oct 2019 10:33:42 +0000 Subject: [PATCH] Fix omp target issue with Fortran optional arguments gcc/ * omp-low.c (lower_omp_target): Dereference optional argument to work with the right pointer. gcc/testsuite/ * libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-1.f90: New. From-SVN: r276445 --- gcc/ChangeLog | 5 +++ gcc/omp-low.c | 2 +- gcc/testsuite/ChangeLog | 4 +++ .../use_device_ptr-optional-1.f90 | 36 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-1.f90 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7e467035d1b..6f577c36d64 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-10-02 Tobias Burnus + + * omp-low.c (lower_omp_target): Dereference optional argument + to work with the right pointer. + 2019-10-02 Kwok Cheung Yeung * langhooks-def.h (LANG_HOOKS_OMP_IS_OPTIONAL_ARGUMENT): Default to diff --git a/gcc/omp-low.c b/gcc/omp-low.c index a0e5041d3f2..ca7dfdb83a1 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -11870,7 +11870,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) var = build_fold_addr_expr (var); else { - if (omp_is_reference (ovar)) + if (omp_is_reference (ovar) || omp_is_optional_argument (ovar)) { type = TREE_TYPE (type); if (TREE_CODE (type) != ARRAY_TYPE diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4cb43036465..d95e6e753f2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-10-02 Tobias Burnus + + * libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-1.f90: New. + 2019-10-02 Jakub Jelinek PR tree-optimization/91940 diff --git a/libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-1.f90 b/libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-1.f90 new file mode 100644 index 00000000000..93c61216034 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/use_device_ptr-optional-1.f90 @@ -0,0 +1,36 @@ +! Test whether use_device_ptr properly handles OPTIONAL arguments +! (Only case of present arguments is tested) +program test_it + implicit none + integer, target :: ixx + integer, pointer :: ptr_i, ptr_null + + ptr_i => ixx + call foo(ptr_i) + + ptr_null => null() + call bar(ptr_null) +contains + subroutine foo(ii) + integer, pointer, optional :: ii + + if (.not.present(ii)) call abort() + if (.not.associated(ii, ixx)) call abort() + !$omp target data map(to:ixx) use_device_ptr(ii) + if (.not.present(ii)) call abort() + if (.not.associated(ii)) call abort() + !$omp end target data + end subroutine foo + + ! For bar, it is assumed that a NULL ptr on the host maps to NULL on the device + subroutine bar(jj) + integer, pointer, optional :: jj + + if (.not.present(jj)) call abort() + if (associated(jj)) call abort() + !$omp target data map(to:ixx) use_device_ptr(jj) + if (.not.present(jj)) call abort() + if (associated(jj)) call abort() + !$omp end target data + end subroutine bar +end program test_it -- 2.30.2