Bug 33370

Summary: [4.3 Regression] Structure component arrays
Product: gcc Reporter: Thomas Koenig <tkoenig>
Component: fortranAssignee: Paul Thomas <pault>
Status: RESOLVED FIXED    
Severity: critical CC: burnus, gcc-bugs
Priority: P3 Keywords: wrong-code
Version: 4.3.0   
Target Milestone: ---   
Host: Target:
Build: Known to work: 4.1.3 4.2.1
Known to fail: 4.3.0 Last reconfirmed: 2007-09-10 07:20:46
Bug Depends on:    
Bug Blocks: 32834    

Description Thomas Koenig 2007-09-09 19:31:51 UTC
... doesn't work:

$ cat foo.f90
program main
  type foo
     integer :: i
     character(len=2) :: c
  end type foo
  type(foo), dimension(4) :: a
  a%i = (/ 12, 2, 3, 10 /)
  a%c = 'xy'
  print *,maxval(a%i)
  print *,maxloc(a%i)
  call bar(a%i)
contains
  subroutine bar(b)
    integer, dimension(:) :: b
    print *,b
  end subroutine bar
end program main
$ gfortran foo.f90
$ ./a.out
          68
           3
          12           3          68           0
Comment 1 Thomas Koenig 2007-09-09 20:03:43 UTC
Reduced testcase due to Paul Thomas:

$ cat > goo.f90
program main
  type foo
    integer :: i
     character(len=3) :: c
  end type foo
  type(foo), dimension(4), target :: a
  a%i = (/ 12, 2, 3, 10 /)
  print *, a%i
end program main
$ gfortran goo.f90 
$ ./a.out
          12           3          68           0

Confirmed.
Comment 2 Tobias Burnus 2007-09-10 06:20:42 UTC
gfortran 4.2:
  struct foo a[4];
    int4 A.1[4];
    struct array1_int4 atmp.0;
    [...]
      static int4 data.3[4] = {12, 2, 3, 10};
      __builtin_memcpy (&(*(int4[0:] *) atmp.0.data)[0], &data.3, 16);
      [...]
  a[NON_LVALUE_EXPR<S.4>].i = (*(int4[0:] *) atmp.0.data)[NON_LVALUE_EXPR<S.4>];


gfortran 4.3:
  struct foo a[4];
  static int4 A.1[4] = {12, 2, 3, 10};
  (void) __builtin_memcpy ((void *) &a, (void *) &A.1, 32);
Comment 3 Paul Thomas 2007-09-10 07:20:46 UTC
I am just about to commit as 'obvious' a patch that bootstraps and regtests on x86_ia64/FC5

Paul
Comment 4 Paul Thomas 2007-09-10 07:54:29 UTC
Subject: Bug 33370

Author: pault
Date: Mon Sep 10 07:54:17 2007
New Revision: 128325

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128325
Log:
2007-09-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/33370
	* trans-expr.c (copyable_array_p):  Add tests that expression
	is a variable, that it has no subreferences and that it is a
	full array.
	(gfc_trans_assignment): Change conditions to suit modifications
	to copyable_array_p.

2007-09-10  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/33370
	* gfortran.dg/array_memcpy_5.f90:  New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/array_memcpy_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Paul Thomas 2007-09-10 07:57:38 UTC
Fixed under the 'obvious' rule.

Paul