[committed] OpenMP: Add libgomp.fortran/target-enter-data-8.f90

2025-04-23 Thread Tobias Burnus

Looking through old patches, I came across this testcase.

It was originally part of the patch

[Patch] Fortran/OpenMP: Fix DT struct-component with 'alloc' and array descr
https://gcc.gnu.org/pipermail/gcc-patches/2022-November/604887.html

under the name testsuite/libgomp.fortran/target-enter-data-3.f90
or testsuite/libgomp.fortran/target-enter-data-3a.f90

And I think the code change landed as part of:
r15-9488-g99cd28c4733c2f Fortran/OpenMP: Support automatic mapping 
allocatable components (deep mapping) The history is a bit murky as the 
original patch was submitted 2022, landed in OG12 and was forward ported 
to OG14 with patches merged. In OG14, the code change is gone 
(presumably merged into a code change) and only the test case remained 
in commit: 06a430ade09 Fortran/OpenMP: Fix DT struct-component with 
'alloc' and array descr This commit is essentially that test case; 
however, I checked whether some #if 0 could be removed - and indeed all 
but one could be removed, i.e. more code actually works - whether fixed 
on the generic gfortran side or on the OpenMP, I don't know but I also 
don't care as long as it works :-) Committed as r16-92-gc9a8f2f9d39a31 
Tobias
commit c9a8f2f9d39a317ed67fb47157a995ea03c182d4
Author: Tobias Burnus 
Date:   Wed Apr 23 09:03:00 2025 +0200

OpenMP: Add libgomp.fortran/target-enter-data-8.f90

Add another testcase for Fortran deep mapping of allocatable components.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/target-enter-data-8.f90: New test.

diff --git a/libgomp/testsuite/libgomp.fortran/target-enter-data-8.f90 b/libgomp/testsuite/libgomp.fortran/target-enter-data-8.f90
new file mode 100644
index 000..c6d671c1306
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/target-enter-data-8.f90
@@ -0,0 +1,532 @@
+! { dg-additional-options "-cpp" }
+
+! FIXME: Some tests do not work yet. Those are for now in '#if 0'
+
+! Check that 'map(alloc:' properly works with
+! - deferred-length character strings
+! - arrays with array descriptors
+! For those, the array descriptor / string length must be mapped with 'to:'
+
+program main
+implicit none
+
+type t
+  integer :: ic(2:5), ic2
+  character(len=11) :: ccstr(3:4), ccstr2
+  character(len=11,kind=4) :: cc4str(3:7), cc4str2
+  integer, pointer :: pc(:), pc2
+  character(len=:), pointer :: pcstr(:), pcstr2
+  character(len=:,kind=4), pointer :: pc4str(:), pc4str2
+end type t
+
+type(t) :: dt
+
+integer :: ii(5), ii2
+character(len=11) :: clstr(-1:1), clstr2
+character(len=11,kind=4) :: cl4str(0:3), cl4str2
+integer, pointer :: ip(:), ip2
+integer, allocatable :: ia(:), ia2
+character(len=:), pointer :: pstr(:), pstr2
+character(len=:), allocatable :: astr(:), astr2
+character(len=:,kind=4), pointer :: p4str(:), p4str2
+character(len=:,kind=4), allocatable :: a4str(:), a4str2
+
+
+allocate(dt%pc(5), dt%pc2)
+allocate(character(len=2) :: dt%pcstr(2))
+allocate(character(len=4) :: dt%pcstr2)
+
+allocate(character(len=3,kind=4) :: dt%pc4str(2:3))
+allocate(character(len=5,kind=4) :: dt%pc4str2)
+
+allocate(ip(5), ip2, ia(8), ia2)
+allocate(character(len=2) :: pstr(-2:0))
+allocate(character(len=4) :: pstr2)
+allocate(character(len=6) :: astr(3:5))
+allocate(character(len=8) :: astr2)
+
+allocate(character(len=3,kind=4) :: p4str(2:4))
+allocate(character(len=5,kind=4) :: p4str2)
+allocate(character(len=7,kind=4) :: a4str(-2:3))
+allocate(character(len=9,kind=4) :: a4str2)
+
+
+! integer :: ic(2:5), ic2
+
+!$omp target enter data map(alloc: dt%ic)
+!$omp target map(alloc: dt%ic)
+  if (size(dt%ic) /= 4) error stop
+  if (lbound(dt%ic, 1) /= 2) error stop
+  if (ubound(dt%ic, 1) /= 5) error stop
+  dt%ic = [22, 33, 44, 55]
+!$omp end target
+!$omp target exit data map(from: dt%ic)
+if (size(dt%ic) /= 4) error stop
+if (lbound(dt%ic, 1) /= 2) error stop
+if (ubound(dt%ic, 1) /= 5) error stop
+if (any (dt%ic /= [22, 33, 44, 55])) error stop
+
+!$omp target enter data map(alloc: dt%ic2)
+!$omp target map(alloc: dt%ic2)
+  dt%ic2 = 42
+!$omp end target
+!$omp target exit data map(from: dt%ic2)
+if (dt%ic2 /= 42) error stop
+
+
+! character(len=11) :: ccstr(3:4), ccstr2
+
+!$omp target enter data map(alloc: dt%ccstr)
+!$omp target map(alloc: dt%ccstr)
+  if (len(dt%ccstr) /= 11) error stop
+  if (size(dt%ccstr) /= 2) error stop
+  if (lbound(dt%ccstr, 1) /= 3) error stop
+  if (ubound(dt%ccstr, 1) /= 4) error stop
+  dt%ccstr = ["12345678901", "abcdefghijk"]
+!$omp end target
+!$omp target exit data map(from: dt%ccstr)
+if (len(dt%ccstr) /= 11) error stop
+if (size(dt%ccstr) /= 2) error stop
+if (lbound(dt%ccstr, 1) /= 3) error stop
+if (ubound(dt%ccstr, 1) /= 4) error stop
+if (any (dt%ccstr /= ["12345678901", "abcdefghijk"])) error stop
+
+!$omp target enter data map(alloc: dt%ccstr2)
+!$omp target map(alloc: dt%ccstr2)
+  if (len(dt%ccstr2) /= 11) error stop
+  dt%ccstr2 = "ABCDEFGHIJK"
+!$omp end target
+!$omp target exit data map(from: dt%ccstr2)
+if (len(dt%ccstr2) /= 11) error 

Re: [Fortran, Patch, PR119200, v1] Use correct locus while check()ing coarray functions.

2025-04-23 Thread Andre Vehreschild
Hi Harald,

thanks for the review.

> this is bordering on the obvious and thus OK, except for:

Well, it wasn't so obvious, when was able to add a mistake ;-)

I have fixed that and committed as gcc-16-94-gcc2716a3f52.

Thanks again for the review,
Andre

> 
> @@ -6967,7 +6972,8 @@ gfc_check_ucobound (gfc_expr *coarray, gfc_expr 
> *dim, gfc_expr *kind)
>   {
> if (flag_coarray == GFC_FCOARRAY_NONE)
>   {
> -  gfc_fatal_error ("Coarrays disabled at %C, use %<-fcoarray=%> to 
> enable");
> +  gfc_fatal_error ("Coarrays disabled at L, use %<-fcoarray=%> to 
> enable",
> +  gfc_current_intrinsic_where);
> return false;
>   }
> 
> A percent is missing.  It should read "%L", not "L".
> 
> > This error does not crash gfortran reliably. But valgrind
> > reports an access to uninitialized memory. I therefore do not know how to
> > test this in the testsuite.  
> 
> I don't know a reasonable way to test this either.  There is one
> existing test with dg-error "Coarrays disabled..., but the issue
> addressed here might show up only in an instrumented compiler
> (ASAN or UBSAN?).  And since each message here is emitted by
> gfc_fatal_error(), one could only test one case per testcase.
> (IMHO testing this would be insane.)
> 
> > Regtests ok on x86_64-pc-linux-gnu / F41. Ok for mainline?  
> 
> Yes, this is OK.  Thanks for the patch!
> 
> Harald
> 
> > Regards,
> > Andre  
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de