From 693be70f589682c0c65ce92c4602d481aa7f16e3 Mon Sep 17 00:00:00 2001 From: Julian Brown Date: Wed, 23 Apr 2025 03:11:29 +0000 Subject: OpenACC: Allow implicit uses of assumed-size arrays in offload regions This patch reimplements the functionality of the previously-reverted patch "Assumed-size arrays with non-lexical data mappings". The purpose is to support implicit uses of assumed-size arrays for Fortran when those arrays have already been mapped on the target some other way (e.g. by "acc enter data"). This relates to upstream OpenACC issue 489 (not yet resolved). gcc/fortran/ * trans-openmp.cc (gfc_omp_finish_clause): Treat implicitly-mapped assumed-size arrays as zero-sized for OpenACC, rather than an error. gcc/testsuite/ * gfortran.dg/goacc/assumed-size.f90: Don't expect error. libgomp/ * testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-1.f90: New test. * testsuite/libgomp.oacc-fortran/nonlexical-assumed-size-2.f90: New test. --- gcc/fortran/trans-openmp.cc | 16 ++++++++++++---- gcc/testsuite/gfortran.dg/goacc/assumed-size.f90 | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'gcc') diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index c28d937..cfecdb0 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -1595,6 +1595,7 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc) tree decl = OMP_CLAUSE_DECL (c); location_t loc = OMP_CLAUSE_LOCATION (c); + bool assumed_size = false; /* Assumed-size arrays can't be mapped implicitly, they have to be mapped explicitly using array sections. */ @@ -1605,9 +1606,14 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc) GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)) - 1) == NULL) { - error_at (OMP_CLAUSE_LOCATION (c), - "implicit mapping of assumed size array %qD", decl); - return; + if (openacc) + assumed_size = true; + else + { + error_at (OMP_CLAUSE_LOCATION (c), + "implicit mapping of assumed size array %qD", decl); + return; + } } if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR) @@ -1662,7 +1668,9 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc) else { OMP_CLAUSE_DECL (c) = decl; - OMP_CLAUSE_SIZE (c) = NULL_TREE; + OMP_CLAUSE_SIZE (c) = assumed_size ? size_zero_node : NULL_TREE; + if (assumed_size) + OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; } if (TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE && (GFC_DECL_GET_SCALAR_POINTER (orig_decl) diff --git a/gcc/testsuite/gfortran.dg/goacc/assumed-size.f90 b/gcc/testsuite/gfortran.dg/goacc/assumed-size.f90 index 4fced2e..12f44c4 100644 --- a/gcc/testsuite/gfortran.dg/goacc/assumed-size.f90 +++ b/gcc/testsuite/gfortran.dg/goacc/assumed-size.f90 @@ -4,7 +4,8 @@ ! exit data, respectively. ! This does not appear to be supported by the OpenACC standard as of version -! 3.0. Check for an appropriate error message. +! 3.0. There is however real-world code that relies on this working, so we +! make an attempt to support it. program test implicit none @@ -26,7 +27,6 @@ subroutine dtest (a, n) !$acc enter data copyin(a(1:n)) !$acc parallel loop -! { dg-error {implicit mapping of assumed size array 'a'} "" { target *-*-* } .-1 } do i = 1, n a(i) = i end do -- cgit v1.1