From ae740ccecdd59110782f3c0623486df14a57d7b7 Mon Sep 17 00:00:00 2001
From: Thomas Koenig <Thomas.Koenig@online.de>
Date: Tue, 7 Jun 2005 20:46:17 +0000
Subject: [PATCH] re PR libfortran/21926 ([4.0 only] matmul does not deal with
 non-packed result)

2005-06-07  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/21926
	* m4/matmul.m4:  Correct zeroing of result for non-packed
	arrays with lowest stride is one.
	* generated/matmul_c4.c:  Regenerated.
	* generated/matmul_c8.c:  Regenerated.
	* generated/matmul_i4.c:  Regenerated.
	* generated/matmul_i8.c:  Regenerated.
	* generated/matmul_r4.c:  Regenerated.
	* generated/matmul_r8.c:  Regenerated.

2005-06-07  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/21926
	* gfortran.fortran-torture/execute/intrinsic_matmul.f90:
	Test case where the return array has lowest stride one,
	but isn't packed.

From-SVN: r100721
---
 gcc/testsuite/ChangeLog                              |  7 +++++++
 .../execute/intrinsic_matmul.f90                     |  8 ++++++++
 libgfortran/ChangeLog                                | 12 ++++++++++++
 libgfortran/generated/matmul_c4.c                    |  9 ++++++++-
 libgfortran/generated/matmul_c8.c                    |  9 ++++++++-
 libgfortran/generated/matmul_i4.c                    |  9 ++++++++-
 libgfortran/generated/matmul_i8.c                    |  9 ++++++++-
 libgfortran/generated/matmul_r4.c                    |  9 ++++++++-
 libgfortran/generated/matmul_r8.c                    |  9 ++++++++-
 libgfortran/m4/matmul.m4                             |  9 ++++++++-
 10 files changed, 83 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7aacd2f36686..ef8a58fcd571 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2005-06-07  Thomas Koenig  <Thomas.Koenig@online.de>
+
+	PR libfortran/21926
+	* gfortran.fortran-torture/execute/intrinsic_matmul.f90:
+	Test case where the return array has lowest stride one,
+	but isn't packed.
+
 2005-06-07  Adrian Straetling  <straetling@de.ibm.com>
 
 	* lib/target-supports.exp (check_effective_target_sync_int_long):
diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_matmul.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_matmul.f90
index 4b195d267bd1..9364f1e1d8b0 100644
--- a/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_matmul.f90
+++ b/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_matmul.f90
@@ -7,6 +7,8 @@ program intrinsic_matmul
    integer, dimension(3) :: y
    integer, dimension(2, 2) :: r
    integer, dimension(3) :: v
+   real, dimension (2,2) :: aa
+   real, dimension (4,2) :: cc
 
    a = reshape((/1, 2, 2, 3, 3, 4/), (/2, 3/))
    b = reshape((/1, 2, 3, 3, 4, 5/), (/3, 2/))
@@ -21,4 +23,10 @@ program intrinsic_matmul
 
    v(1:2) = matmul(a, y)
    if (any(v(1:2) .ne. (/14, 20/))) call abort
+
+  aa = reshape((/ 1.0, 1.0, 0.0, 1.0/), shape(aa))
+  cc = 42.
+  cc(1:2,1:2) = matmul(aa, transpose(aa))
+  if (any(cc(1:2,1:2) .ne. reshape((/ 1.0, 1.0, 1.0, 2.0 /), (/2,2/)))) call abort
+  if (any(cc(3:4,1:2) .ne. 42.)) call abort
 end program
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index b912b31adcf5..ac9fce5281b7 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,15 @@
+2005-06-07  Thomas Koenig  <Thomas.Koenig@online.de>
+
+	PR libfortran/21926
+	* m4/matmul.m4:  Correct zeroing of result for non-packed
+	arrays with lowest stride is one.
+	* generated/matmul_c4.c:  Regenerated.
+	* generated/matmul_c8.c:  Regenerated.
+	* generated/matmul_i4.c:  Regenerated.
+	* generated/matmul_i8.c:  Regenerated.
+	* generated/matmul_r4.c:  Regenerated.
+	* generated/matmul_r8.c:  Regenerated.
+
 2005-05-30  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
 	PR libfortran/20179
diff --git a/libgfortran/generated/matmul_c4.c b/libgfortran/generated/matmul_c4.c
index 5eb8b44631ba..c63d343ea82e 100644
--- a/libgfortran/generated/matmul_c4.c
+++ b/libgfortran/generated/matmul_c4.c
@@ -178,7 +178,14 @@ matmul_c4 (gfc_array_c4 * retarray, gfc_array_c4 * a, gfc_array_c4 * b)
       GFC_COMPLEX_4 *abase_n;
       GFC_COMPLEX_4 bbase_yn;
 
-      memset (dest, 0, (sizeof (GFC_COMPLEX_4) * size0((array_t *) retarray)));
+      if (rystride == ycount)
+	memset (dest, 0, (sizeof (GFC_COMPLEX_4) * size0((array_t *) retarray)));
+      else
+	{
+	  for (y = 0; y < ycount; y++)
+	    for (x = 0; x < xcount; x++)
+	      dest[x + y*rystride] = (GFC_COMPLEX_4)0;
+	}
 
       for (y = 0; y < ycount; y++)
 	{
diff --git a/libgfortran/generated/matmul_c8.c b/libgfortran/generated/matmul_c8.c
index 181f4c9cc4d1..98326d135d89 100644
--- a/libgfortran/generated/matmul_c8.c
+++ b/libgfortran/generated/matmul_c8.c
@@ -178,7 +178,14 @@ matmul_c8 (gfc_array_c8 * retarray, gfc_array_c8 * a, gfc_array_c8 * b)
       GFC_COMPLEX_8 *abase_n;
       GFC_COMPLEX_8 bbase_yn;
 
-      memset (dest, 0, (sizeof (GFC_COMPLEX_8) * size0((array_t *) retarray)));
+      if (rystride == ycount)
+	memset (dest, 0, (sizeof (GFC_COMPLEX_8) * size0((array_t *) retarray)));
+      else
+	{
+	  for (y = 0; y < ycount; y++)
+	    for (x = 0; x < xcount; x++)
+	      dest[x + y*rystride] = (GFC_COMPLEX_8)0;
+	}
 
       for (y = 0; y < ycount; y++)
 	{
diff --git a/libgfortran/generated/matmul_i4.c b/libgfortran/generated/matmul_i4.c
index f214ba5ec0c8..9dde570b73a4 100644
--- a/libgfortran/generated/matmul_i4.c
+++ b/libgfortran/generated/matmul_i4.c
@@ -178,7 +178,14 @@ matmul_i4 (gfc_array_i4 * retarray, gfc_array_i4 * a, gfc_array_i4 * b)
       GFC_INTEGER_4 *abase_n;
       GFC_INTEGER_4 bbase_yn;
 
-      memset (dest, 0, (sizeof (GFC_INTEGER_4) * size0((array_t *) retarray)));
+      if (rystride == ycount)
+	memset (dest, 0, (sizeof (GFC_INTEGER_4) * size0((array_t *) retarray)));
+      else
+	{
+	  for (y = 0; y < ycount; y++)
+	    for (x = 0; x < xcount; x++)
+	      dest[x + y*rystride] = (GFC_INTEGER_4)0;
+	}
 
       for (y = 0; y < ycount; y++)
 	{
diff --git a/libgfortran/generated/matmul_i8.c b/libgfortran/generated/matmul_i8.c
index 5e0e6a792f96..18d877e20f99 100644
--- a/libgfortran/generated/matmul_i8.c
+++ b/libgfortran/generated/matmul_i8.c
@@ -178,7 +178,14 @@ matmul_i8 (gfc_array_i8 * retarray, gfc_array_i8 * a, gfc_array_i8 * b)
       GFC_INTEGER_8 *abase_n;
       GFC_INTEGER_8 bbase_yn;
 
-      memset (dest, 0, (sizeof (GFC_INTEGER_8) * size0((array_t *) retarray)));
+      if (rystride == ycount)
+	memset (dest, 0, (sizeof (GFC_INTEGER_8) * size0((array_t *) retarray)));
+      else
+	{
+	  for (y = 0; y < ycount; y++)
+	    for (x = 0; x < xcount; x++)
+	      dest[x + y*rystride] = (GFC_INTEGER_8)0;
+	}
 
       for (y = 0; y < ycount; y++)
 	{
diff --git a/libgfortran/generated/matmul_r4.c b/libgfortran/generated/matmul_r4.c
index b6014d0dbce5..642dc9438377 100644
--- a/libgfortran/generated/matmul_r4.c
+++ b/libgfortran/generated/matmul_r4.c
@@ -178,7 +178,14 @@ matmul_r4 (gfc_array_r4 * retarray, gfc_array_r4 * a, gfc_array_r4 * b)
       GFC_REAL_4 *abase_n;
       GFC_REAL_4 bbase_yn;
 
-      memset (dest, 0, (sizeof (GFC_REAL_4) * size0((array_t *) retarray)));
+      if (rystride == ycount)
+	memset (dest, 0, (sizeof (GFC_REAL_4) * size0((array_t *) retarray)));
+      else
+	{
+	  for (y = 0; y < ycount; y++)
+	    for (x = 0; x < xcount; x++)
+	      dest[x + y*rystride] = (GFC_REAL_4)0;
+	}
 
       for (y = 0; y < ycount; y++)
 	{
diff --git a/libgfortran/generated/matmul_r8.c b/libgfortran/generated/matmul_r8.c
index 5bf21f60404c..1eb53cd6c673 100644
--- a/libgfortran/generated/matmul_r8.c
+++ b/libgfortran/generated/matmul_r8.c
@@ -178,7 +178,14 @@ matmul_r8 (gfc_array_r8 * retarray, gfc_array_r8 * a, gfc_array_r8 * b)
       GFC_REAL_8 *abase_n;
       GFC_REAL_8 bbase_yn;
 
-      memset (dest, 0, (sizeof (GFC_REAL_8) * size0((array_t *) retarray)));
+      if (rystride == ycount)
+	memset (dest, 0, (sizeof (GFC_REAL_8) * size0((array_t *) retarray)));
+      else
+	{
+	  for (y = 0; y < ycount; y++)
+	    for (x = 0; x < xcount; x++)
+	      dest[x + y*rystride] = (GFC_REAL_8)0;
+	}
 
       for (y = 0; y < ycount; y++)
 	{
diff --git a/libgfortran/m4/matmul.m4 b/libgfortran/m4/matmul.m4
index dd75cf7b0738..1801583f0262 100644
--- a/libgfortran/m4/matmul.m4
+++ b/libgfortran/m4/matmul.m4
@@ -180,7 +180,14 @@ sinclude(`matmul_asm_'rtype_code`.m4')dnl
       rtype_name *abase_n;
       rtype_name bbase_yn;
 
-      memset (dest, 0, (sizeof (rtype_name) * size0((array_t *) retarray)));
+      if (rystride == ycount)
+	memset (dest, 0, (sizeof (rtype_name) * size0((array_t *) retarray)));
+      else
+	{
+	  for (y = 0; y < ycount; y++)
+	    for (x = 0; x < xcount; x++)
+	      dest[x + y*rystride] = (rtype_name)0;
+	}
 
       for (y = 0; y < ycount; y++)
 	{
-- 
GitLab