[Flang] Compilation error for pointer-returning internal functions
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This was discovered by @claude.
Consider the following code:
```fortran
program main
implicit none
integer :: f_called = 0
integer :: g_called = 0
integer, target :: target_val = 0
ptr_f() = val_g()
if (f_called == 1 .and. g_called == 1 .and. target_val == 42) then
print *, "pass"
else
print *, "FAIL: f_called =", f_called, " g_called =", g_called, &
" target_val =", target_val
end if
contains
function ptr_f() result(p)
integer, pointer :: p
f_called = f_called + 1
p => target_val
end function ptr_f
function val_g() result(v)
integer :: v
g_called = g_called + 1
v = 42
end function val_g
end program main
```
Flang and GFortran reject this code: https://godbolt.org/z/oMfdKGrdn
If the functions are defined in a module instead of the main program, both compilers accept it.
Contributor guide
Research direction
Start with the Fortran reproducer in the issue and compare its behavior with the module-defined version shown in the report. Reproduce the rejection in Flang, then trace the handling of pointer-returning internal functions and verify that the program compiles and produces the expected pass output.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100