Bug ID: 81735
           Summary: double free or corruption (fasttop) error (SIGABRT)
                    with character(:) and custom return type with
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot
          Reporter: flashmozzg at gmail dot com
  Target Milestone: ---

This error appears at least starting from gfortran 5.4.0 and is present in
gfortran 7.1.0.
I've tested on Ubuntu 16.04. I've also tested on Win10 x64 with gfortran
bundled with MinGW (from Qt installation) with versions 4.9.2 and 5.3.0 and
couldn't reproduce it there.
I compiled using gfortran -std=f2008 -ffree-form -g -Wall -o foo.f95

I've managed to reduce the program to this small sample:

program fooprog
    implicit none
    type FooType
        integer, allocatable :: x
    end type FooType

    type(FooType), pointer :: bar

    bar => foo()

    function foo() result(res)
        type(FooType), pointer :: res

        character(:), allocatable :: rt
        rt = ""
        res => null()
    end function foo
end program fooprog

Compiling and running it results in a SIGABRT with

*** Error in `./foo': double free or corruption (fasttop): 0x0000000001cff0a0
======= Backtrace: =========
... etc

Important: if I comment rt = "". the problem doesn't occur.
If res has a basic type, the problem doesn't occur.
If x in FooType is not marked allocatable, the problem doesn't occur.

Reply via email to