From 8eeeecbcc17041fdfd3ccc928161ae86e7f9b456 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 3 Sep 2020 20:33:14 +0200 Subject: [PATCH] PR fortran/96890 - Wrong answer with intrinsic IALL The IALL intrinsic would always return 0 when the DIM and MASK arguments were present since the initial value of repeated BIT-AND operations was set to 0 instead of -1. libgfortran/ChangeLog: * m4/iall.m4: Initial value for result should be -1. * generated/iall_i1.c (miall_i1): Generated. * generated/iall_i16.c (miall_i16): Likewise. * generated/iall_i2.c (miall_i2): Likewise. * generated/iall_i4.c (miall_i4): Likewise. * generated/iall_i8.c (miall_i8): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/iall_masked.f90: New test. --- gcc/testsuite/gfortran.dg/iall_masked.f90 | 22 ++++++++++++++++++++++ libgfortran/generated/iall_i1.c | 2 +- libgfortran/generated/iall_i16.c | 2 +- libgfortran/generated/iall_i2.c | 2 +- libgfortran/generated/iall_i4.c | 2 +- libgfortran/generated/iall_i8.c | 2 +- libgfortran/m4/iall.m4 | 2 +- 7 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/iall_masked.f90 diff --git a/gcc/testsuite/gfortran.dg/iall_masked.f90 b/gcc/testsuite/gfortran.dg/iall_masked.f90 new file mode 100644 index 00000000000..33cc4106a1b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/iall_masked.f90 @@ -0,0 +1,22 @@ +! { dg-do run } +! PR fortran/96890 - Wrong answer with intrinsic IALL +program p + implicit none + integer :: iarr1(0), iarr2(2,2), iarr3(2,2,2) + logical :: mask1(0), mask2(2,2), mask3(2,2,2) + + if ( iall(iarr1, mask1) /= -1 ) stop 1 + if ( iall(iarr1, 1, mask1) /= -1 ) stop 2 + + iarr2 = reshape ([ 1, 2, 3, 4 ], shape (iarr2)) + mask2 = reshape ([ .true., .false., .true., .false. ], shape (mask2)) + + if (any (iall(iarr2, 2, mask2) /= [1,-1]) ) stop 3 + + iarr3 = reshape ([ 1, 2, 3, 4, & + 5, 6, 7, 8 ], shape (iarr3)) + mask3 = reshape ([ .true., .false., .true., .false.,& + .true., .false., .true., .false. ], shape (iarr3)) + + if (any (iall(iarr3, 2, mask3) /= reshape ([1,-1,5,-1],[2,2]))) stop 4 +end diff --git a/libgfortran/generated/iall_i1.c b/libgfortran/generated/iall_i1.c index 3fe0a1698ad..086a5464aad 100644 --- a/libgfortran/generated/iall_i1.c +++ b/libgfortran/generated/iall_i1.c @@ -345,7 +345,7 @@ miall_i1 (gfc_array_i1 * const restrict retarray, msrc = mbase; { - result = 0; + result = (GFC_INTEGER_1) -1; for (n = 0; n < len; n++, src += delta, msrc += mdelta) { diff --git a/libgfortran/generated/iall_i16.c b/libgfortran/generated/iall_i16.c index 35d9872c0e9..c491414ca7c 100644 --- a/libgfortran/generated/iall_i16.c +++ b/libgfortran/generated/iall_i16.c @@ -345,7 +345,7 @@ miall_i16 (gfc_array_i16 * const restrict retarray, msrc = mbase; { - result = 0; + result = (GFC_INTEGER_16) -1; for (n = 0; n < len; n++, src += delta, msrc += mdelta) { diff --git a/libgfortran/generated/iall_i2.c b/libgfortran/generated/iall_i2.c index ef90119341f..d43e5df1809 100644 --- a/libgfortran/generated/iall_i2.c +++ b/libgfortran/generated/iall_i2.c @@ -345,7 +345,7 @@ miall_i2 (gfc_array_i2 * const restrict retarray, msrc = mbase; { - result = 0; + result = (GFC_INTEGER_2) -1; for (n = 0; n < len; n++, src += delta, msrc += mdelta) { diff --git a/libgfortran/generated/iall_i4.c b/libgfortran/generated/iall_i4.c index 27140abeaa8..039e7963798 100644 --- a/libgfortran/generated/iall_i4.c +++ b/libgfortran/generated/iall_i4.c @@ -345,7 +345,7 @@ miall_i4 (gfc_array_i4 * const restrict retarray, msrc = mbase; { - result = 0; + result = (GFC_INTEGER_4) -1; for (n = 0; n < len; n++, src += delta, msrc += mdelta) { diff --git a/libgfortran/generated/iall_i8.c b/libgfortran/generated/iall_i8.c index 6047169c62e..d01f7aecaf8 100644 --- a/libgfortran/generated/iall_i8.c +++ b/libgfortran/generated/iall_i8.c @@ -345,7 +345,7 @@ miall_i8 (gfc_array_i8 * const restrict retarray, msrc = mbase; { - result = 0; + result = (GFC_INTEGER_8) -1; for (n = 0; n < len; n++, src += delta, msrc += mdelta) { diff --git a/libgfortran/m4/iall.m4 b/libgfortran/m4/iall.m4 index df57367c100..8f3b7741486 100644 --- a/libgfortran/m4/iall.m4 +++ b/libgfortran/m4/iall.m4 @@ -35,7 +35,7 @@ ARRAY_FUNCTION(0, ` result &= *src;') MASKED_ARRAY_FUNCTION(0, -` result = 0;', +` result = ('rtype_name`) -1;', ` if (*msrc) result &= *src;') -- 2.30.2