This is an archive of the discontinued LLVM Phabricator instance.

[flang] catch implicit interface incompatibility with global scope symbol
ClosedPublic

Authored by jeanPerier on Feb 8 2022, 12:08 PM.

Details

Summary

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.

Diff Detail

Event Timeline

jeanPerier created this revision.Feb 8 2022, 12:08 PM
jeanPerier requested review of this revision.Feb 8 2022, 12:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 8 2022, 12:08 PM
klausler accepted this revision.Feb 8 2022, 12:17 PM

Looks great! Thanks for looking into this problem.

This revision is now accepted and ready to land.Feb 8 2022, 12:17 PM