While experimenting with testcases from PR31320, I hit this:

$> cat alloc.f90
TYPE :: x
  INTEGER, ALLOCATABLE :: a(:)
END TYPE
TYPE(x) :: a

a = x((/ 1, 2, 3 /))
a = x((/ a%a, 4 /))
end

$> gfortran-svn -g -Wall -fdump-tree-original allocatable.f90 && ./a.out
Segmentation fault

$> valgrind --tool=memcheck --leak-check=full ./a.out
[...]
==2287== Invalid read of size 4
==2287==    at 0x804895F: MAIN__ (allocatable.f90:8)
==2287==    by 0x8048C78: main (fmain.c:22)
==2287==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==2287==
==2287== Process terminating with default action of signal 11 (SIGSEGV)
==2287==  Access not within mapped region at address 0x0
==2287==    at 0x804895F: MAIN__ (allocatable.f90:8)
==2287==    by 0x8048C78: main (fmain.c:22)

>From trre-dump:
[...]
     _gfortran_deallocate (a.a.data, &D.1050);
      a.a.data = 0B;
[...]
        D.1029 = (int4[0:] *) a.a.data;
[...]
          while (1)
            {
              if (S.6 > a.a.dim[0].ubound) goto L.1;
              (*(int4[0:] *) atmp.4.data)[offset.5] = (*D.1029)[S.6 * D.1034 +
D.1030];
              offset.5 = offset.5 + 1;
              S.6 = S.6 + 1;
            }
          L.1:;


$> gcc version 4.3.0 20070705 (experimental)


-- 
           Summary: allocatable array on lhs deleted while still in use on
                    rhs
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dfranke at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32665

Reply via email to