[patch, libfortran] Fix for PR 21127, complex reshape

Thomas Koenig Thomas.Koenig@online.de
Fri Apr 29 20:29:00 GMT 2005


This fixes PR 21127.

Regression-tested on mainline.  OK for mainline?

WRT 4.0:  I am not sure what the policy for 4.0.1 is.  This patch
changes the library interface by removing reshape_4 and reshape_8
and replacing them with reshape_i4 and reshape_i8, respectively.

Is this OK (in principle, once regression tests pass) for 4.0?

2005-04-29  Thomas Koenig  <Thomas.Koenig@online.de>

	* fortran/iresolve.c (gfc_resolve_reshape): Add 
	gfc_type_letter (BT_COMPLEX) for complex and
	gfc_type_letter (BT_INTEGER) for integer, real or
	logical to resolved function name.

2005-04-29  Thomas Koenig  <Thomas.Koenig@online.de>

	* Makefile.am:  Add generated/reshape_c4.c and
	generated/reshape_c8.c.
	* Makefile.in:  Regenerated.
	* m4/reshape.m4:  Use rtype_code instead of rtype_kind
	in function name.
	* generated/reshape_i4.c: Regenerated.
	* generated/reshape_i8.c: Regenerated.
	* generated/reshape_c4.c: New file.
	* generated/reshape_c8.c: New file.
	
2005-04-29  Thomas Koenig  <Thomas.Koenig@online.de>

	* gfortran.dg/reshape-complex.f90:  New test.
-------------- next part --------------
Index: gcc/fortran/iresolve.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/iresolve.c,v
retrieving revision 1.33
diff -c -r1.33 iresolve.c
*** gcc/fortran/iresolve.c	22 Mar 2005 22:08:14 -0000	1.33
--- gcc/fortran/iresolve.c	29 Apr 2005 20:09:10 -0000
***************
*** 1109,1114 ****
--- 1109,1115 ----
    mpz_t rank;
    int kind;
    int i;
+   int type_letter;
  
    f->ts = source->ts;
  
***************
*** 1119,1130 ****
--- 1120,1133 ----
      {
      case BT_COMPLEX:
        kind = source->ts.kind * 2;
+       type_letter = gfc_type_letter (BT_COMPLEX);
        break;
  
      case BT_REAL:
      case BT_INTEGER:
      case BT_LOGICAL:
        kind = source->ts.kind;
+       type_letter = gfc_type_letter (BT_INTEGER);
        break;
  
      default:
***************
*** 1138,1144 ****
      case 8:
      /* case 16: */
        f->value.function.name =
! 	gfc_get_string (PREFIX("reshape_%d"), source->ts.kind);
        break;
  
      default:
--- 1141,1147 ----
      case 8:
      /* case 16: */
        f->value.function.name =
! 	gfc_get_string (PREFIX("reshape_%c%d"), type_letter, source->ts.kind);
        break;
  
      default:
Index: libgfortran/m4/reshape.m4
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/m4/reshape.m4,v
retrieving revision 1.8
diff -c -r1.8 reshape.m4
*** libgfortran/m4/reshape.m4	22 Apr 2005 20:02:44 -0000	1.8
--- libgfortran/m4/reshape.m4	29 Apr 2005 20:09:11 -0000
***************
*** 40,51 ****
     return array.  */
  dnl Only the kind (ie size) is used to name the function.
  
! extern void reshape_`'rtype_kind (rtype *, rtype *, shape_type *,
  				    rtype *, shape_type *);
! export_proto(reshape_`'rtype_kind);
  
  void
! reshape_`'rtype_kind (rtype * ret, rtype * source, shape_type * shape,
                        rtype * pad, shape_type * order)
  {
    /* r.* indicates the return array.  */
--- 40,51 ----
     return array.  */
  dnl Only the kind (ie size) is used to name the function.
  
! extern void reshape_`'rtype_code (rtype *, rtype *, shape_type *,
  				    rtype *, shape_type *);
! export_proto(reshape_`'rtype_code);
  
  void
! reshape_`'rtype_code (rtype * ret, rtype * source, shape_type * shape,
                        rtype * pad, shape_type * order)
  {
    /* r.* indicates the return array.  */
Index: libgfortran/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/Makefile.am,v
retrieving revision 1.32
diff -c -r1.32 Makefile.am
*** libgfortran/Makefile.am	7 Apr 2005 21:06:24 -0000	1.32
--- libgfortran/Makefile.am	29 Apr 2005 20:09:12 -0000
***************
*** 227,233 ****
  
  i_reshape_c= \
  generated/reshape_i4.c \
! generated/reshape_i8.c
  
  i_eoshift1_c= \
  generated/eoshift1_4.c \
--- 227,235 ----
  
  i_reshape_c= \
  generated/reshape_i4.c \
! generated/reshape_i8.c \
! generated/reshape_c4.c \
! generated/reshape_c8.c
  
  i_eoshift1_c= \
  generated/eoshift1_4.c \
-------------- next part --------------
! { dg-do run }
! PR 21127:  Reshape of complex didn't work.
program main
  complex, dimension(8) :: b
  complex, dimension(2,2) :: a
  integer :: i
  b = (/(i,i=1,8)/)
  a = reshape(b(1:8:2),shape(a))
  if (a(1,1) /= (1.0, 0.0) .or. a(2,1) /= (3.0, 0.0) .or.  &
      a(1,2) /= (5.0, 0.0) .or. a(2,2) /= (7.0, 0.0)) call abort
end


More information about the Gcc-patches mailing list