Issue 184377
Summary [flang] trampolines created inside internal procedures should have the lifetime of the host procedure
Labels flang:fir-hlfir
Assignees
Reporter jeanPerier
    Currently, trampolines created when assigning an internal procedure to a pointer are created on the stack of the procedure that contains the pointer assignment.

When the procedure pointer assignment happens inside an internal procedure, this is not in line with the Fortran requirements that the lifetime of the pointer target is the one of the host procedure (not the internal procedure).

For instance, when compiled at -O0, the following program will segfault.

```
module m
 implicit none
 procedure(), pointer :: proc_ptr
contains
subroutine host_procedure()
  integer :: x
 x = 1
  call internal_proc1()
  print *, "covering the stack from previous internal_proc1 call"
  x = 2
  call proc_ptr()
contains
  subroutine internal_proc1()
    proc_ptr => internal_proc2
  end subroutine
 subroutine internal_proc2()
    print *, x
  end subroutine
end subroutine
end module

  use m
  call host_procedure()
end
```

A potential solution is to create the trampolines used inside internal procedures in the host and to pass them via the hidden argument (as if they were extra variables from the host being addressed in internal procedures).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to