[libgfortran] patch PR18857

THOMAS Paul Richard 169137 prthomas@drfccad.cea.fr
Thu Apr 28 12:15:00 GMT 2005


The following patch and testsuite program address the failure of matmul to
treat the majority of likely values for the component base of the input and
output gfc_arrays.  In fact, base is not used, like other functions in
libgfortran.  Thus the asserts that base should be 0 does nothing and causes
the failure.  I believe that the rest of the function and certainly survives
every test that I can throw at it.

Is the testsuite program too much?  It could be reduced to two cases, in
order to test the disappearance of the source of the PR.

Bootstrapped and regtested on Cygwin-NT_5.0/i686/XP - OK to commit?

Please note previous remark about Windows Explorer and tabs.  The patch is
OK.

Paul T

2005-04-28  Paul Thomas  <pault@gcc.gnu.org>

	PR libfortran/18857
	* generated/matmul_c4.c:
	* generated/matmul_c8.c:
	* generated/matmul_i4.c:
	* generated/matmul_i8.c:
	* generated/matmul_r4.c:
	* generated/matmul_r8.c:
	* m4/matmul.m4: Removes assertions that component base of the
	input and output gfc_array structures should be 0 for all 7
functions.


Index: gcc/libgfortran/generated/matmul_c4.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/generated/matmul_c4.c,v
retrieving revision 1.8
diff -p -c -3 -r1.8 matmul_c4.c
*** gcc/libgfortran/generated/matmul_c4.c	12 Jan 2005 21:27:32 -0000
1.8
--- gcc/libgfortran/generated/matmul_c4.c	28 Apr 2005 11:31:53 -0000
*************** matmul_c4 (gfc_array_c4 * retarray, gfc_
*** 167,176 ****
        ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
      }
  
-   assert (a->base == 0);
-   assert (b->base == 0);
-   assert (retarray->base == 0);
- 
    abase = a->data;
    bbase = b->data;
    dest = retarray->data;
--- 167,172 ----
Index: gcc/libgfortran/generated/matmul_c8.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/generated/matmul_c8.c,v
retrieving revision 1.8
diff -p -c -3 -r1.8 matmul_c8.c
*** gcc/libgfortran/generated/matmul_c8.c	12 Jan 2005 21:27:32 -0000
1.8
--- gcc/libgfortran/generated/matmul_c8.c	28 Apr 2005 11:31:53 -0000
*************** matmul_c8 (gfc_array_c8 * retarray, gfc_
*** 167,176 ****
        ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
      }
  
-   assert (a->base == 0);
-   assert (b->base == 0);
-   assert (retarray->base == 0);
- 
    abase = a->data;
    bbase = b->data;
    dest = retarray->data;
--- 167,172 ----
Index: gcc/libgfortran/generated/matmul_i4.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/generated/matmul_i4.c,v
retrieving revision 1.8
diff -p -c -3 -r1.8 matmul_i4.c
*** gcc/libgfortran/generated/matmul_i4.c	12 Jan 2005 21:27:32 -0000
1.8
--- gcc/libgfortran/generated/matmul_i4.c	28 Apr 2005 11:31:53 -0000
*************** matmul_i4 (gfc_array_i4 * retarray, gfc_
*** 167,176 ****
        ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
      }
  
-   assert (a->base == 0);
-   assert (b->base == 0);
-   assert (retarray->base == 0);
- 
    abase = a->data;
    bbase = b->data;
    dest = retarray->data;
--- 167,172 ----
Index: gcc/libgfortran/generated/matmul_i8.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/generated/matmul_i8.c,v
retrieving revision 1.8
diff -p -c -3 -r1.8 matmul_i8.c
*** gcc/libgfortran/generated/matmul_i8.c	12 Jan 2005 21:27:32 -0000
1.8
--- gcc/libgfortran/generated/matmul_i8.c	28 Apr 2005 11:31:53 -0000
*************** matmul_i8 (gfc_array_i8 * retarray, gfc_
*** 167,176 ****
        ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
      }
  
-   assert (a->base == 0);
-   assert (b->base == 0);
-   assert (retarray->base == 0);
- 
    abase = a->data;
    bbase = b->data;
    dest = retarray->data;
--- 167,172 ----
Index: gcc/libgfortran/generated/matmul_r4.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/generated/matmul_r4.c,v
retrieving revision 1.8
diff -p -c -3 -r1.8 matmul_r4.c
*** gcc/libgfortran/generated/matmul_r4.c	12 Jan 2005 21:27:32 -0000
1.8
--- gcc/libgfortran/generated/matmul_r4.c	28 Apr 2005 11:31:54 -0000
*************** matmul_r4 (gfc_array_r4 * retarray, gfc_
*** 167,176 ****
        ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
      }
  
-   assert (a->base == 0);
-   assert (b->base == 0);
-   assert (retarray->base == 0);
- 
    abase = a->data;
    bbase = b->data;
    dest = retarray->data;
--- 167,172 ----
Index: gcc/libgfortran/generated/matmul_r8.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/generated/matmul_r8.c,v
retrieving revision 1.8
diff -p -c -3 -r1.8 matmul_r8.c
*** gcc/libgfortran/generated/matmul_r8.c	12 Jan 2005 21:27:32 -0000
1.8
--- gcc/libgfortran/generated/matmul_r8.c	28 Apr 2005 11:31:54 -0000
*************** matmul_r8 (gfc_array_r8 * retarray, gfc_
*** 167,176 ****
        ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
      }
  
-   assert (a->base == 0);
-   assert (b->base == 0);
-   assert (retarray->base == 0);
- 
    abase = a->data;
    bbase = b->data;
    dest = retarray->data;
--- 167,172 ----
Index: gcc/libgfortran/m4/matmul.m4
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/m4/matmul.m4,v
retrieving revision 1.9
diff -p -c -3 -r1.9 matmul.m4
*** gcc/libgfortran/m4/matmul.m4	12 Jan 2005 21:27:31 -0000	1.9
--- gcc/libgfortran/m4/matmul.m4	28 Apr 2005 11:31:54 -0000
*************** sinclude(`matmul_asm_'rtype_code`.m4')dn
*** 169,178 ****
        ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
      }
  
-   assert (a->base == 0);
-   assert (b->base == 0);
-   assert (retarray->base == 0);
- 
    abase = a->data;
    bbase = b->data;
    dest = retarray->data;
--- 169,174 ----  


----------------------------testsuite/gfortran.dg/pr18857.f90---------------
----------

!{ dg-do run }
! Test MATMUL for various kinds of array.
! PR18857 was due to an incorrect assertion that component base==0
! for both input arguments and the result.
! provided by Paul Thomas - pault@gcc.gnu.org

program pr18857
  integer, parameter                                :: N = 5
  integer, parameter                                :: T = 4
  real(kind=T), dimension(:,:), allocatable, Target :: a, b, c
  real(kind=T), dimension(:,:), pointer             :: d, e
  real(kind=T), dimension(N,N)                      :: x, y, z

  allocate (a(2*N, N), b(N, N), c(2*N, N))
  a = 1.0_T
  a(1:N,:) = 2.0_T
  b = 4.0_T
  x = 1.0_T
  y = 2.0_T

  z = 0.0_T
  z = matmul (x, y)
  if (sum (z) /= 250.0_T) call abort ()

  c = 0.0_T
  c = matmul (a, b)
  if (sum (c) /= 1500.0_T) call abort ()   ! It would be sufficient to stop
here.

  c = 0.0_T
  c = matmul (a(:,3:N), b(3:N,:))
  if (sum (c) /= 900.0_T) call abort ()

  c = 0.0_T
  d => a(1 : N, 1:N)
  c = matmul (d, b)
  if (sum (c) /= 1000.0_T) call abort ()

  c = 0.0_T
  d => a(N+1 : 2*N, 1:N)
  c = matmul (d, b)
  if (sum (c) /= 500.0_T) call abort ()

  c = 0.0_T
  d => a(N+1 : 2*N, 1:N)
  c = matmul (b, d)
  if (sum (c) /= 500.0_T) call abort ()

  c = 0.0_T
  e => c(N+1 : 2*N, 1 : N)
  e = matmul (d, b)
  if (sum (c(1 : N, 1 : N)) /= 0.0_T) call abort ()
  if (sum (c(N+1 : 2*N, 1 : N)) /= 500.0_T) call abort ()

  call doitagain (a ,b ,c ,x ,y ,z )

  deallocate (a, b, c)

contains

  subroutine doitagain (a ,b ,c ,x ,y ,z )
    real(kind=T), dimension(5:, 5:)    ::  a ,b ,c ,x ,y ,z

    z = 0.0_T
    z = matmul (x, y)
    if (sum (z) /= 250.0_T) call abort ()

    c = 0.0_T
    c = matmul (a, b)
    if (sum (c) /= 1500.0_T) call abort ()

  end subroutine doitagain

end program pr18857



More information about the Gcc-patches mailing list