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.
This commit is contained in:
Harald Anlauf 2020-09-03 20:33:14 +02:00
parent 753b4679bc
commit 8eeeecbcc1
7 changed files with 28 additions and 6 deletions

View File

@ -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

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -35,7 +35,7 @@ ARRAY_FUNCTION(0,
` result &= *src;')
MASKED_ARRAY_FUNCTION(0,
` result = 0;',
` result = ('rtype_name`) -1;',
` if (*msrc)
result &= *src;')