llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Flang] Allocation of an extension type causes a runtime error

Open boo-aboutme opened this issue 10 months ago • 1 comments

Version of flang: 23.0.0git (https://github.com/llvm/llvm-project.git eb773961aac45593ce126ed258d82c3c3abbaa93)
Target: aarch64-unknown-linux-gnu

The executable object compiled with Flang for the following program causes a runtime error when allocating a variable of an extension type.

Expected behavior: The program should compile and run successfully, printing "test.f90 : pass" without errors.

$ flang test.f90
$ ./a.out
Fatal glibc error: malloc.c:2492 (sysmalloc): assertion failed: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)

test.f90

module mod
  type :: b
    integer::d1
    type (e),allocatable::n
    integer::dd1(1000)
  end type
  type,extends(b) :: e
    integer::d2
    character(:),allocatable::c
  end type
  contains
  subroutine alloc(d)
    class (b),allocatable :: d
    allocate(e::d)
  end subroutine alloc
  subroutine s1
    class (b),allocatable :: v
    call alloc(v)
    deallocate(v)
  end
end module mod
use mod
  call s1
  print *,'test.f90 : pass'
end

Results of other compilers:

Intel Ifx:

$ ifx --version
ifx (IFX) 2024.2.1 20240711
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

$ ifx test.f90
$ ./a.out
 test.f90 : pass

Fujitsu frt:

$ frt --version
frt (FRT) 4.12.1 20250711
Copyright FUJITSU LIMITED 2019-2025
$ frt test.f90
$ ./a.out
 test.f90 : pass

GNU gfortran: (x86-64 gfortran 15.1 on compiler explorer)

Program returned: 0
Program stdout
 test.f90 : pass

boo-aboutme avatar Jan 30 '26 00:01 boo-aboutme

@llvm/issue-subscribers-flang-frontend

Author: Manabu Matsuyama (boo-aboutme)

``` text Version of flang: 23.0.0git (https://github.com/llvm/llvm-project.git eb773961aac45593ce126ed258d82c3c3abbaa93) Target: aarch64-unknown-linux-gnu ```

The executable object compiled with Flang for the following program causes a runtime error when allocating a variable of an extension type.

Expected behavior: The program should compile and run successfully, printing "test.f90 : pass" without errors.

$ flang test.f90
$ ./a.out
Fatal glibc error: malloc.c:2492 (sysmalloc): assertion failed: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)

test.f90

module mod
  type :: b
    integer::d1
    type (e),allocatable::n
    integer::dd1(1000)
  end type
  type,extends(b) :: e
    integer::d2
    character(:),allocatable::c
  end type
  contains
  subroutine alloc(d)
    class (b),allocatable :: d
    allocate(e::d)
  end subroutine alloc
  subroutine s1
    class (b),allocatable :: v
    call alloc(v)
    deallocate(v)
  end
end module mod
use mod
  call s1
  print *,'test.f90 : pass'
end

Results of other compilers:

Intel Ifx:

$ ifx --version
ifx (IFX) 2024.2.1 20240711
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

$ ifx test.f90
$ ./a.out
 test.f90 : pass

Fujitsu frt:

$ frt --version
frt (FRT) 4.12.1 20250711
Copyright FUJITSU LIMITED 2019-2025
$ frt test.f90
$ ./a.out
 test.f90 : pass

GNU gfortran: (x86-64 gfortran 15.1 on compiler explorer)

Program returned: 0
Program stdout
 test.f90 : pass

llvmbot avatar Feb 01 '26 02:02 llvmbot