Skip to content

Segmentation fault compiling function returning pointer #12674

Description

@ivan-pi
! assoc_kinds.f90
module m
  implicit none
  real, target :: tgt(2:4) = [20., 30., 40.]
contains
  function f_ptr() result(p)
    real, pointer :: p(:)
    p => tgt
  end function
  function f_val() result(w)
    real :: w(3)
    w = [1., 2., 3.]
  end function
end module

program assoc_kinds
  use m
  implicit none

  ! --- function results ---
  associate (fv => f_val(), fp => f_ptr())
    print *, 'lbound(f_val())     =', lbound(fv)
    print *, 'lbound(f_ptr())     =', lbound(fp)
    fp(2) = -20.        ! pointer-function ref is a VARIABLE => definable!
  end associate
  print *, 'tgt after write via fp =', tgt
end program
$ /opt/homebrew/Cellar/micromamba/2.5.0_4/bin/lfortran fortran/assoc_kinds.f90
Segmentation fault: 11
$ /opt/homebrew/Cellar/micromamba/2.5.0_4/bin/lfortran --version
LFortran version: 0.62.0
Status: alpha (expected to fail on third-party codes)
Platform: macOS ARM
LLVM: 19.1.1
Default target: arm64-apple-darwin25.6.0
LSP Version: 3.17.0
JSON_RPC Version: 2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions