[patch, Fortran] FINDLOC for unsigned
Hello world, here's another small patch for FINDLOC for unsigned. OK for trunk? Best regards Thomas Implement FINDLOC for UNSIGNED. gcc/fortran/ChangeLog: * check.cc (intrinsic_type_check): Handle unsigned. (gfc_check_findloc): Likewise. * gfortran.texi: Include FINDLOC in unsigned documentation. * iresolve.cc (gfc_resolve_findloc): Use INTEGER version for UNSIGNED. gcc/testsuite/ChangeLog: * gfortran.dg/unsigned_33.f90: New test.From 864071a00f886ae2115d6dfa5d286c84e67360f6 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Sat, 28 Sep 2024 19:10:08 +0200 Subject: [PATCH] Implement FINDLOC for UNSIGNED. gcc/fortran/ChangeLog: * check.cc (intrinsic_type_check): Handle unsigned. (gfc_check_findloc): Likewise. * gfortran.texi: Include FINDLOC in unsigned documentation. * iresolve.cc (gfc_resolve_findloc): Use INTEGER version for UNSIGNED. gcc/testsuite/ChangeLog: * gfortran.dg/unsigned_33.f90: New test. --- gcc/fortran/check.cc | 5 +- gcc/fortran/gfortran.texi | 3 +- gcc/fortran/iresolve.cc | 9 ++- gcc/testsuite/gfortran.dg/unsigned_33.f90 | 76 +++ 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/unsigned_33.f90 diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc index 1da269f5b72..dd79a49a0c9 100644 --- a/gcc/fortran/check.cc +++ b/gcc/fortran/check.cc @@ -643,7 +643,7 @@ intrinsic_type_check (gfc_expr *e, int n) { if (e->ts.type != BT_INTEGER && e->ts.type != BT_REAL && e->ts.type != BT_COMPLEX && e->ts.type != BT_CHARACTER - && e->ts.type != BT_LOGICAL) + && e->ts.type != BT_LOGICAL && e->ts.type != BT_UNSIGNED) { gfc_error ("%qs argument of %qs intrinsic at %L must be of intrinsic type", gfc_current_intrinsic_arg[n]->name, @@ -4267,6 +4267,9 @@ gfc_check_findloc (gfc_actual_arglist *ap) if ((a1 && !v1) || (!a1 && v1)) goto incompat; + if (flag_unsigned && gfc_invalid_unsigned_ops (a,v)) +goto incompat; + /* Check the kind of the characters argument match. */ if (a1 && v1 && a->ts.kind != v->ts.kind) goto incompat; diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index b42d0095e57..7aa16428867 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -2791,7 +2791,8 @@ As of now, the following intrinsics take unsigned arguments: @item @code{SUM}, @code{PRODUCT}, @code{MATMUL} and @code{DOT_PRODUCT} @item @code{IANY}, @code{IALL} and @code{IPARITY} @item @code{RANDOM_NUMBER} -@item @code{CSHIFT} and @code{EOSHIFT}. +@item @code{CSHIFT} and @code{EOSHIFT} +@item @code{FINDLOC}. @end itemize This list will grow in the near future. @c - diff --git a/gcc/fortran/iresolve.cc b/gcc/fortran/iresolve.cc index 5a1e0a6ed1d..9fb22128492 100644 --- a/gcc/fortran/iresolve.cc +++ b/gcc/fortran/iresolve.cc @@ -1819,6 +1819,7 @@ gfc_resolve_findloc (gfc_expr *f, gfc_expr *array, gfc_expr *value, int i, j, idim; int fkind; int d_num; + bt type; /* See at the end of the function for why this is necessary. */ @@ -1897,9 +1898,15 @@ gfc_resolve_findloc (gfc_expr *f, gfc_expr *array, gfc_expr *value, gfc_convert_type_warn (back, &ts, 2, 0); } + /* Use the INTEGER library function for UNSIGNED. */ + if (array->ts.type != BT_UNSIGNED) +type = array->ts.type; + else +type = BT_INTEGER; + f->value.function.name = gfc_get_string (PREFIX ("%s%d_%c%d"), name, d_num, - gfc_type_letter (array->ts.type, true), + gfc_type_letter (type, true), gfc_type_abi_kind (&array->ts)); /* We only have a single library function, so we need to convert diff --git a/gcc/testsuite/gfortran.dg/unsigned_33.f90 b/gcc/testsuite/gfortran.dg/unsigned_33.f90 new file mode 100644 index 000..7ff11e6c9bb --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unsigned_33.f90 @@ -0,0 +1,76 @@ +! { dg-do run } +! { dg-options "-funsigned" } +! Check compile-time simplification of FINDLOC +! Mostly lifted from findloc_5.f90. +program memain + implicit none + call test1 + call test2 +contains + subroutine test1 +unsigned, dimension(4) :: a1 +integer :: i1, i2, i3, i4 +unsigned, dimension(2,2) :: a, b +integer, dimension(2) :: t8, t9, t10 +unsigned, dimension(2,3) :: c +integer, dimension(3) :: t13 +integer, dimension(2) :: t14 + +a1 = [1u, 2u, 3u, 1u] +i1 = findloc(a1, 1u, dim=1) +if (i1 /= 1) stop 1 +i2 = findloc(a1, 2u, dim=1) +if (i2 /= 2) stop 2 +i3 = findloc(a1,3u, dim=1) +if (i3 /= 3) stop 3 +i4 = findloc(a1, 1u, dim=1, back=.true.) +if (i4 /= 4) stop 4 +a = reshape([1u,2u,3u,4u], [2,2]) +b = reshape([1u,2u,1u,2u], [2,2]) +t8 = findloc(a,5u) +if (any(t8 /= [0,0])) stop 8 +t9 = findloc(a,5u,back=.true.) +if (any(t9
Re: [patch, Fortran] CSHIFT and EOSHIFT for unsigned
OK. Thanks for the patch. -- steve On Sat, Sep 28, 2024 at 09:33:20AM +0200, Thomas Koenig wrote: > > this patch, consisting almost entirely of the test cases, implements > CSHIFT and EOSHIFT for unsigneds. > > OK for trunk? > > Implement CSHIFT and EOSHIFT for unsigned. > > gcc/fortran/ChangeLog: > > * check.cc (gfc_check_eoshift): Handle BT_UNSIGNED. > * simplify.cc (gfc_simplify_eoshift): Likewise. > * gfortran.texi: Document CSHIFT and EOSHIFT for UNSIGNED. > > gcc/testsuite/ChangeLog: > > * gfortran.dg/unsigned_31.f90: New test. > * gfortran.dg/unsigned_32.f90: New test. > From d73e3fff882de4ea8e7412e47a3f257f0ca12cd7 Mon Sep 17 00:00:00 2001 > From: Thomas Koenig > Date: Thu, 26 Sep 2024 21:46:55 +0200 > Subject: [PATCH] Implement CSHIFT and EOSHIFT for unsigned. > > gcc/fortran/ChangeLog: > > * check.cc (gfc_check_eoshift): Handle BT_UNSIGNED. > * simplify.cc (gfc_simplify_eoshift): Likewise. > * gfortran.texi: Document CSHIFT and EOSHIFT for UNSIGNED. > > gcc/testsuite/ChangeLog: > > * gfortran.dg/unsigned_31.f90: New test. > * gfortran.dg/unsigned_32.f90: New test. > --- > gcc/fortran/check.cc | 6 + > gcc/fortran/gfortran.texi | 3 ++- > gcc/fortran/simplify.cc | 4 > gcc/testsuite/gfortran.dg/unsigned_31.f90 | 27 +++ > gcc/testsuite/gfortran.dg/unsigned_32.f90 | 27 +++ > 5 files changed, 66 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gfortran.dg/unsigned_31.f90 > create mode 100644 gcc/testsuite/gfortran.dg/unsigned_32.f90 > > diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc > index 1851cfb8d4a..1da269f5b72 100644 > --- a/gcc/fortran/check.cc > +++ b/gcc/fortran/check.cc > @@ -3073,6 +3073,12 @@ gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, > gfc_expr *boundary, > case BT_CHARACTER: > break; > > + case BT_UNSIGNED: > + if (flag_unsigned) > + break; > + > + gcc_fallthrough(); > + > default: > gfc_error ("Missing %qs argument to %qs intrinsic at %L for %qs " >"of type %qs", gfc_current_intrinsic_arg[2]->name, > diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi > index a5ebadff3bb..b42d0095e57 100644 > --- a/gcc/fortran/gfortran.texi > +++ b/gcc/fortran/gfortran.texi > @@ -2790,7 +2790,8 @@ As of now, the following intrinsics take unsigned > arguments: > @item @code{TRANSFER} > @item @code{SUM}, @code{PRODUCT}, @code{MATMUL} and @code{DOT_PRODUCT} > @item @code{IANY}, @code{IALL} and @code{IPARITY} > -@item @code{RANDOM_NUMBER}. > +@item @code{RANDOM_NUMBER} > +@item @code{CSHIFT} and @code{EOSHIFT}. > @end itemize > This list will grow in the near future. > @c - > diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc > index bd2f6485c95..2f6c3c39dad 100644 > --- a/gcc/fortran/simplify.cc > +++ b/gcc/fortran/simplify.cc > @@ -2630,6 +2630,10 @@ gfc_simplify_eoshift (gfc_expr *array, gfc_expr > *shift, gfc_expr *boundary, > bnd = gfc_get_int_expr (array->ts.kind, NULL, 0); > break; > > + case BT_UNSIGNED: > + bnd = gfc_get_unsigned_expr (array->ts.kind, NULL, 0); > + break; > + > case BT_LOGICAL: > bnd = gfc_get_logical_expr (array->ts.kind, NULL, 0); > break; > diff --git a/gcc/testsuite/gfortran.dg/unsigned_31.f90 > b/gcc/testsuite/gfortran.dg/unsigned_31.f90 > new file mode 100644 > index 000..2a7c08ddba8 > --- /dev/null > +++ b/gcc/testsuite/gfortran.dg/unsigned_31.f90 > @@ -0,0 +1,27 @@ > +! { dg-do run } > +! { dg-options "-funsigned" } > +program memain > + call test1 > + call test2 > +contains > + subroutine test1 > +unsigned, dimension(3) :: v > +unsigned, dimension(3,3) :: w, x > +integer, dimension(3) :: shft > +v = [1u, 2u, 3u] > +if (any(eoshift(v,1) /= [2u,3u,0u])) error stop 1 > +w = reshape([1u,2u,3u,4u,5u,6u,7u,8u,9u],[3,3]) > +x = eoshift(w, shift=[1,-2,1], boundary=10u, dim=1) > +if (any(x /= reshape([2u,3u,10u,10u,10u,4u,8u,9u,10u],[3,3]))) error > stop 2 > +shft = [2,-1,-2] > +x = eoshift(w,shift=shft,boundary=20u,dim=2) > +if (any(x /= reshape([7u,20u,20u,20u,2u,20u,20u,5u,3u],[3,3]))) error > stop 3 > + end subroutine test1 > + subroutine test2 > +unsigned, dimension(3), parameter :: v = eoshift([1u,2u,3u],1) > +unsigned, dimension(3,3), parameter :: w = > reshape([1u,2u,3u,4u,5u,6u,7u,8u,9u],[3,3]) > +unsigned, dimension(3,3), parameter :: x = eoshift(w,shift=[1,-2,1], > boundary=10u, dim=1) > +if (any(v /= [2u,3u,0u])) error stop 11 > +if (any(x /= reshape([2u,3u,10u,10u,10u,4u,8u,9u,10u],[3,3]))) error > stop 2 > + end subroutine test2 > +end program memain > diff --git a/gcc/testsuite/gfortran.dg/uns
Re: [patch, Fortran] FINDLOC for unsigned
On Sat, Sep 28, 2024 at 08:32:00PM +0200, Thomas Koenig wrote: > Hello world, > > here's another small patch for FINDLOC for unsigned. > > OK for trunk? > OK. Other than UNSIGNED being a new experimental feature, this patch almost qualifies as "Obvious". -- Steve
Re: [patch, Fortran] FINDLOC for unsigned
Am 28.09.24 um 21:14 schrieb Steve Kargl: On Sat, Sep 28, 2024 at 08:32:00PM +0200, Thomas Koenig wrote: Hello world, here's another small patch for FINDLOC for unsigned. OK for trunk? OK. Other than UNSIGNED being a new experimental feature, this patch almost qualifies as "Obvious". Both patches are committed now. Thanks for the review! Best regards Thomas
[patch, Fortran] CSHIFT and EOSHIFT for unsigned
Hello world, this patch, consisting almost entirely of the test cases, implements CSHIFT and EOSHIFT for unsigneds. OK for trunk? Implement CSHIFT and EOSHIFT for unsigned. gcc/fortran/ChangeLog: * check.cc (gfc_check_eoshift): Handle BT_UNSIGNED. * simplify.cc (gfc_simplify_eoshift): Likewise. * gfortran.texi: Document CSHIFT and EOSHIFT for UNSIGNED. gcc/testsuite/ChangeLog: * gfortran.dg/unsigned_31.f90: New test. * gfortran.dg/unsigned_32.f90: New test.From d73e3fff882de4ea8e7412e47a3f257f0ca12cd7 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Thu, 26 Sep 2024 21:46:55 +0200 Subject: [PATCH] Implement CSHIFT and EOSHIFT for unsigned. gcc/fortran/ChangeLog: * check.cc (gfc_check_eoshift): Handle BT_UNSIGNED. * simplify.cc (gfc_simplify_eoshift): Likewise. * gfortran.texi: Document CSHIFT and EOSHIFT for UNSIGNED. gcc/testsuite/ChangeLog: * gfortran.dg/unsigned_31.f90: New test. * gfortran.dg/unsigned_32.f90: New test. --- gcc/fortran/check.cc | 6 + gcc/fortran/gfortran.texi | 3 ++- gcc/fortran/simplify.cc | 4 gcc/testsuite/gfortran.dg/unsigned_31.f90 | 27 +++ gcc/testsuite/gfortran.dg/unsigned_32.f90 | 27 +++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/unsigned_31.f90 create mode 100644 gcc/testsuite/gfortran.dg/unsigned_32.f90 diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc index 1851cfb8d4a..1da269f5b72 100644 --- a/gcc/fortran/check.cc +++ b/gcc/fortran/check.cc @@ -3073,6 +3073,12 @@ gfc_check_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary, case BT_CHARACTER: break; + case BT_UNSIGNED: + if (flag_unsigned) + break; + + gcc_fallthrough(); + default: gfc_error ("Missing %qs argument to %qs intrinsic at %L for %qs " "of type %qs", gfc_current_intrinsic_arg[2]->name, diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index a5ebadff3bb..b42d0095e57 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -2790,7 +2790,8 @@ As of now, the following intrinsics take unsigned arguments: @item @code{TRANSFER} @item @code{SUM}, @code{PRODUCT}, @code{MATMUL} and @code{DOT_PRODUCT} @item @code{IANY}, @code{IALL} and @code{IPARITY} -@item @code{RANDOM_NUMBER}. +@item @code{RANDOM_NUMBER} +@item @code{CSHIFT} and @code{EOSHIFT}. @end itemize This list will grow in the near future. @c - diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index bd2f6485c95..2f6c3c39dad 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -2630,6 +2630,10 @@ gfc_simplify_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary, bnd = gfc_get_int_expr (array->ts.kind, NULL, 0); break; + case BT_UNSIGNED: + bnd = gfc_get_unsigned_expr (array->ts.kind, NULL, 0); + break; + case BT_LOGICAL: bnd = gfc_get_logical_expr (array->ts.kind, NULL, 0); break; diff --git a/gcc/testsuite/gfortran.dg/unsigned_31.f90 b/gcc/testsuite/gfortran.dg/unsigned_31.f90 new file mode 100644 index 000..2a7c08ddba8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unsigned_31.f90 @@ -0,0 +1,27 @@ +! { dg-do run } +! { dg-options "-funsigned" } +program memain + call test1 + call test2 +contains + subroutine test1 +unsigned, dimension(3) :: v +unsigned, dimension(3,3) :: w, x +integer, dimension(3) :: shft +v = [1u, 2u, 3u] +if (any(eoshift(v,1) /= [2u,3u,0u])) error stop 1 +w = reshape([1u,2u,3u,4u,5u,6u,7u,8u,9u],[3,3]) +x = eoshift(w, shift=[1,-2,1], boundary=10u, dim=1) +if (any(x /= reshape([2u,3u,10u,10u,10u,4u,8u,9u,10u],[3,3]))) error stop 2 +shft = [2,-1,-2] +x = eoshift(w,shift=shft,boundary=20u,dim=2) +if (any(x /= reshape([7u,20u,20u,20u,2u,20u,20u,5u,3u],[3,3]))) error stop 3 + end subroutine test1 + subroutine test2 +unsigned, dimension(3), parameter :: v = eoshift([1u,2u,3u],1) +unsigned, dimension(3,3), parameter :: w = reshape([1u,2u,3u,4u,5u,6u,7u,8u,9u],[3,3]) +unsigned, dimension(3,3), parameter :: x = eoshift(w,shift=[1,-2,1], boundary=10u, dim=1) +if (any(v /= [2u,3u,0u])) error stop 11 +if (any(x /= reshape([2u,3u,10u,10u,10u,4u,8u,9u,10u],[3,3]))) error stop 2 + end subroutine test2 +end program memain diff --git a/gcc/testsuite/gfortran.dg/unsigned_32.f90 b/gcc/testsuite/gfortran.dg/unsigned_32.f90 new file mode 100644 index 000..7d41988b042 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unsigned_32.f90 @@ -0,0 +1,27 @@ +! { dg-do run } +! { dg-options "-funsigned" } +program memain + call test1 + call test2 +contains + subroutine test1 +unsigned, dimension(3) :: v +unsigned, dimension(3,3) :: w, x +integer, dimension(3) :: shft +v = [1u, 2u, 3u] +if (any(cshift(v,1)