llvm-project/flang/test/Semantics/call24.f90

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
893 B
Fortran
Raw Normal View History

[flang] catch implicit interface incompatibility with global scope symbol Previously, when calling a procedure implicitly for which a global scope procedure symbol with the same name existed, semantics resolved the procedure name in the call to the global symbol without checking that the symbol interface was compatible with the implicit interface of the call. This could cause expression rewrite and lowering to later badly process the implicit call assuming a different result type or an explicit interface. This could lead to lowering crash in case the actual argument were incompatible with the dummies from the explicit interface. Emit errors in the following problematic cases: - If the result type from the symbol did not match the one from the implicit interface. - If the symbol requires an explicit interface. This patch still allows calling an F77 like procedure with different actual argument types than the one it was defined with because it is correctly supported in lowering and is a feature in some program (it is a pointer cast). The two cases that won't be accepted have little chance to make much sense. Results returning ABIs may differ depending on the return types, and function that requires explicit interface usually requires descriptors or specific processing that is incompatible with implicit interfaces. Note that this patch is not making a deep analysis, and it will only catch mistakes if a global symbol and an implicit interface are involved. Cases where the user provided a conflicting explicit interface would still require a pass after name resolution to study conflicts more deeply. But these cases will not crash lowering or trigger expression rewrite to do weird things. Differential Revision: https://reviews.llvm.org/D119274
2022-02-09 16:28:27 +08:00
! RUN: %python %S/test_errors.py %s %flang_fc1
! 15.4.2.2. Test that errors are reported when an explicit interface
! is not provided for an external procedure that requires an explicit
! interface (the definition needs to be visible so that the compiler
! can detect the violation).
subroutine foo(a_pointer)
real, pointer :: a_pointer(:)
end subroutine
subroutine test()
real, pointer :: a_pointer(:)
real, pointer :: an_array(:)
! This call would be allowed if the interface was explicit here,
! but its handling with an implicit interface is different (no
! descriptor involved, copy-in/copy-out...)
!ERROR: References to the procedure 'foo' require an explicit interface
call foo(a_pointer)
! This call would be error if the interface was explicit here.
!ERROR: References to the procedure 'foo' require an explicit interface
call foo(an_array)
end subroutine