[flang-commits] [flang] [Flang] Handle %VAL arguments correctly (PR #157186)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 10 06:35:07 PDT 2025
jeanPerier wrote:
Hi @ceseo, thanks for working on the %VAL fix. I agree a segfault is the expectation for the gfortran test, however, I do not think people will get it with the fix you did.
I think removing the load is not the correct approach because this will cause the compilation of the caller to be lowered differently if the implicit procedure is or not defined in the same file, while implicit calls should not be impacted by the existence of the definition of the definition in the same file. This is because the "compilation unit" concept is not really a Fortran concept, it is an implementation detail. Code move from one compilation unit to another should not affect the semantic of a program.
Basically, we should lower test1 and test2 the same way in this example (just like gfortran) and I do not think it is the case with your fix (see [godbolt link](https://godbolt.org/z/osxEv6o1r)).
```
subroutine sa(x1)
logical::x1
end
subroutine test1(a1)
logical::a1
! Implicit call. sa1 defined in the current compilation unit.
call sa(%val(a1))
end
subroutine test2(a2)
logical::a2
! Implicit call. sa2 not defined in compilation unit.
call sa2(%val(a2))
end
```
I think the correct fix is to force an indirect call to the implicit signature just like `mustCastFuncOpToCopeWithImplicitInterfaceMismatch` is doing for cases without %VAL. There may be a %VAL issue around that logic.
https://github.com/llvm/llvm-project/pull/157186
More information about the flang-commits
mailing list