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

            Bug ID: 89174
           Summary: [8/9 Regression] Allocation segfault with CLASS(*)
                    MOLD
           Product: gcc
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: neil.n.carlson at gmail dot com
  Target Milestone: ---

Some relatively recent change (since ~Sept) has broken 8.2.1 and 9.0. Code that
contained the type of allocation given in the following example used to work
but now segfaults.

module mod
  type :: array_data
    class(*), allocatable :: mold
  contains
    procedure :: push
  end type
contains
  subroutine push(this, value)
    class(array_data), intent(inout) :: this
    class(*), intent(in) :: value
    allocate(this%mold, mold=value) ! <== SEGFAULTS HERE
  end subroutine
end module

use mod
type(array_data) :: foo
call foo%push(42)
end

This example segfaults on the current 8.2.1 and 9.0, but works on 7.3.1. Here's
the output from valgrind:

$ valgrind ./a.out
==18450== Memcheck, a memory error detector
==18450== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==18450== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==18450== Command: ./a.out
==18450== 
==18450== Invalid read of size 2
==18450==    at 0x4C31618: memcpy@GLIBC_2.2.5 (vg_replace_strmem.c:1033)
==18450==    by 0x400D9B: __mod_MOD_push (bug.f90:11)
==18450==    by 0x400E17: MAIN__ (bug.f90:17)
==18450==    by 0x400E4E: main (bug.f90:15)
==18450==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==18450== 

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

Backtrace for this error:
#0  0x5a9f7cf in ???
#1  0x4c31618 in _vgr20181ZZ_libcZdsoZa_memcpyZAGLIBCZu2Zd2Zd5
        at ../shared/vg_replace_strmem.c:1033
#2  0x400d9b in ???
#3  0x400e17 in ???
#4  0x400e4e in ???
#5  0x5a8bfe9 in ???
#6  0x400699 in ???
#7  0xffffffffffffffff in ???
==18450== 
==18450== Process terminating with default action of signal 11 (SIGSEGV):
dumping core
==18450==    at 0x5A9F72E: raise (in /usr/lib64/libc-2.26.so)
==18450==    by 0x5A9F7CF: ??? (in /usr/lib64/libc-2.26.so)
==18450==    by 0x4C31617: memcpy@GLIBC_2.2.5 (vg_replace_strmem.c:1033)
==18450==    by 0x400D9B: __mod_MOD_push (bug.f90:11)
==18450==    by 0x400E17: MAIN__ (bug.f90:17)
==18450==    by 0x400E4E: main (bug.f90:15)

Reply via email to