https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87937

--- Comment #5 from Tomáš Trnka <trnka at scm dot com> ---
Could you please kindly suggest what do I need to do to get this out of
WAITING? I will gladly assist with any debugging and testing, but I'm not well
versed enough with GCC internals to fix the underlying issue myself.

Looks like reallocation is also broken inside "associate" constructs. The
following testcase from pr85954 crashes (when compiled without optimization)
because no allocation code is generated at all. 

$ cat pr85954-z1.f90
program p
   character(:), allocatable :: z(:)
   call s(z)
contains
   subroutine s(x)
      character(:), allocatable :: x(:)
      associate (y => x)
         y = ['abc']
      end associate
      print *, allocated(x), size(x), len(x), x
   end
end
$ gfortran -g -fdump-tree-original pr85954-z1.f90 
$ grep alloc pr85954-z1.f90.003t.original 
$ ./a.out 
 F           0  1002358272
$ ./a.out      

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7fed77d6471e in ???
#1  0x7fed77d638d3 in ???
#2  0x7fed779d55bf in ???
#3  0x7fed77afef0d in ???
#4  0x4012d8 in s
        at /home/trnka/adf/test/gcc-lhs-realloc-87937/pr85954-z1.f90:8
#5  0x401498 in p
        at /home/trnka/adf/test/gcc-lhs-realloc-87937/pr85954-z1.f90:3
#6  0x4014ce in main
        at /home/trnka/adf/test/gcc-lhs-realloc-87937/pr85954-z1.f90:3
Segmentation fault (core dumped)

The issue is less evident at -O1 and above, although the generated code is just
as incorrect. It just doesn't segfault that much but valgrind shows a lot of
uninitialized value errors all over the place.

The variant without an "associate" construct (z2.f90 in pr85954) works fine.

Reply via email to