Skip to content

[Flang] Crash when a function result is used for merge argument #118922

Closed
@kawashima-fj

Description

@kawashima-fj

@jeanPerier #118070 has a regression.

A binary produced by Flang crashes.

Source program:

program main
  implicit none
  type :: ty
    integer, allocatable :: val(:)
  end type
  type(ty) :: a1(1), a2(1), a3(1)
  allocate(a1(1)%val(1), source=1)
  allocate(a2(1)%val(1), source=2)
  allocate(a3(1)%val(1), source=3)
  a3 = merge(f(a1), a2, .true.)
  print *, a3(1)%val(1)
contains
  function f(d) result(r)
    implicit none
    type(ty), intent(in) :: d(:)
    type(ty) :: r(size(d))
    r = d
  end function
end

Run (on AArch64):

$ flang test.f90
$ ./a.out
Segmentation fault (core dumped)

This is detected by Fujitsu Compiler Test Suite run on Linaro CI. The soruce program above is a simplified version of Fujitsu/Fortran/0173/Fujitsu-Fortran-0173_0248.test. I confirmed the commit cd7e653 (#118070) and eb49788 (the latest latest main branch) have this problem but the commit before cd7e653 does not have the problem.

This may be related to #113843, though #113843 is reported before #118070.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions