public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, committed] PR fortran/96890 - Wrong answer with intrinsic IALL
@ 2020-09-03 18:39 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2020-09-03 18:39 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 903 bytes --]

Committed as obvious after regtesting.

The m4 template for the IALL library functions erroneously had a 0
as initial value for the case when the DIM and MASK arguments were
present instead of a -1.  This was unfortunately not tested in the
testsuite before.  Fixed and testcase added.

Thanks,
Harald


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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr96890.patch --]
[-- Type: text/x-patch, Size: 3621 bytes --]

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;')


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-03 18:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03 18:39 [PATCH, committed] PR fortran/96890 - Wrong answer with intrinsic IALL Harald Anlauf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).