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

            Bug ID: 86760
           Summary: FORTRAN: polymorphic arrays inside a user-defined type
                    generate segmentation faults
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hansec at uw dot edu
  Target Milestone: ---

Created attachment 44472
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44472&action=edit
Minimal test case

The attached code produces a segmentation fault when running on MacOS (10.13.6)
and Ubuntu (16.04.4 LTS "GNU/Linux 4.4.0-130-generic x86_64"). The segmentation
fault is produced with GCC 8.1.0 and 8.2.0 when optimization is enabled (-O1 or
greater). It is not produced when optimization is disabled. As far as I can
tell the error is not produced when the source is compiled with GCC 7.x or
earlier. Usage of this pattern has not produced an issue until now with my
production code and the minimal test case attached works as expected with GCC
7.3.0 and 5.4.0.

The crash occurs during the process of deallocating internal structures in a
user-defined type that contains a polymorphic array of pointers where each
pointer element in the array may be a different class. In the attached example,
an object of this type is created and then the deallocation process is
performed deallocating each object in the array after it's local deallocation
method is called. With GFortran 8.1.0 and 8.2.0 the process generates a
segmentation fault on the second item in the array. Note that if a local
intermediary array is used as in the bound method "destroy_local" the
segmentation fault is not produced. Also, note that even though this method
allows different classes in the array only one class is used in this case.

Platform information:

MacOS (10.13.6)-

"uname -a" output (host info removed):

Darwin XXXX 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018;
root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64

"gfortran -v" output:

Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/gcc-8_2/libexec/gcc/x86_64-apple-darwin17.7.0/8.2.0/lto-wrapper
Target: x86_64-apple-darwin17.7.0
Configured with: ../configure --prefix=/opt/gcc-8_2 --with-gmp=/opt/gcc-8_2
--with-mpfr=/opt/gcc-8_2 --with-mpc=/opt/gcc-8_2 --with-isl=/opt/gcc-8_2
--enable-checking=release --enable-languages=c,c++,fortran
--enable-threads=posix
Thread model: posix
gcc version 8.2.0 (GCC)

Ubuntu (16.04.4)-

"uname -a" output (host info removed):

Linux XXXX 4.4.0-130-generic #156-Ubuntu SMP Thu Jun 14 08:53:28 UTC 2018
x86_64 x86_64 x86_64 GNU/Linux

"gfortran -v" output:

Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/gcc-8_1/libexec/gcc/x86_64-pc-linux-gnu/8.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/opt/gcc-8_1 --with-gmp=/opt/gcc-8_1
--with-mpfr=/opt/gcc-8_1 --with-mpc=/opt/gcc-8_1 --with-isl=/opt/gcc-8_1
--enable-checking=release --enable-languages=c,c++,fortran
--enable-threads=posix
Thread model: posix
gcc version 8.1.0 (GCC)

Reply via email to