Skip to content

[flang] Runtime segfault with valid code #156536

@nncarlson

Description

@nncarlson

Here is a small reproducer for a flang bug tripped by our production code. In the example, a call-back subroutine is passed to another subroutine which invokes the call-back. The salient feature which results in the segfault is that the call-back is an internal procedure that accesses a variable from its parent by host association.

module factory

  abstract interface
    subroutine callback
    end subroutine
  end interface

contains

  subroutine alloc_flux_bc
    integer :: n
    n = 42
    call iterate_list(my_cb)
  contains
    subroutine my_cb
      print *, n ! N ACCESSED FROM PARENT BY HOST ASSOCIATION
    end subroutine
  end subroutine
  
  subroutine iterate_list(cb)
    procedure(callback) :: cb
    call cb ! SEGFAULTS HERE
  end subroutine

end module

program main
use factory
call alloc_flux_bc
end program

With the main branch code (as of today), running the compiled code segfaults; the expected output is simply "42". NAG, gfortran, and Intel oneAPI all compile and run this example without error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    flangFlang issues not falling into any other categoryquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions