[PATCH] D119404: [flang] Allow mixed association of procedure pointers and targets

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 9 19:47:54 PST 2022


PeteSteinfeld created this revision.
Herald added a project: Flang.
PeteSteinfeld requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.

Section 10.2.2.4, paragraph 3 states that a procedure pointer with an explicit
interface must have the same characteristics as its target.  Previously, we
interpreted this as disallowing such pointers to point to procedures with
implicit interfaces.  But several other compilers allow this.

This change makes us allow this, also


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119404

Files:
  flang/lib/Evaluate/tools.cpp
  flang/test/Semantics/assign03.f90
  flang/test/Semantics/associated.f90


Index: flang/test/Semantics/associated.f90
===================================================================
--- flang/test/Semantics/associated.f90
+++ flang/test/Semantics/associated.f90
@@ -137,10 +137,8 @@
     realProcPointer1 => intProc
     !ERROR: Procedure pointer 'realprocpointer1' associated with incompatible procedure designator 'intproc'
     lvar = associated(realProcPointer1, intProc)
-    !ERROR: Procedure pointer 'subprocpointer' with explicit interface may not be associated with procedure designator 'externalproc' with implicit interface
-    subProcPointer => externalProc
-    !ERROR: Procedure pointer 'subprocpointer' with explicit interface may not be associated with procedure designator 'externalproc' with implicit interface
-    lvar = associated(subProcPointer, externalProc)
+    subProcPointer => externalProc ! OK to associate a procedure pointer  with an explicit interface to a procedure with an implicit interface
+    lvar = associated(subProcPointer, externalProc) ! OK to associate a procedure pointer with an explicit interface to a procedure with an implicit interface
     !ERROR: Subroutine pointer 'subprocpointer' may not be associated with function designator 'intproc'
     subProcPointer => intProc
     !ERROR: Subroutine pointer 'subprocpointer' may not be associated with function designator 'intproc'
Index: flang/test/Semantics/assign03.f90
===================================================================
--- flang/test/Semantics/assign03.f90
+++ flang/test/Semantics/assign03.f90
@@ -176,8 +176,7 @@
     procedure(s), pointer :: p, q
     procedure(), pointer :: r
     external :: s_external
-    !ERROR: Procedure pointer 'p' with explicit interface may not be associated with procedure designator 's_external' with implicit interface
-    p => s_external
+    p => s_external ! OK for a pointer with an explicit interface to be associated with a procedure with an implicit interface
     r => s_module ! OK for a pointer with implicit interface to be associated with a procedure with an explicit interface.  See 10.2.2.4 (3)
   end
 
Index: flang/lib/Evaluate/tools.cpp
===================================================================
--- flang/lib/Evaluate/tools.cpp
+++ flang/lib/Evaluate/tools.cpp
@@ -970,12 +970,14 @@
           " designator '%s'"_err_en_US;
   } else if (lhsProcedure->HasExplicitInterface() &&
       !rhsProcedure->HasExplicitInterface()) {
+    // OK
     // Section 10.2.2.4, paragraph 3 prohibits associating a procedure pointer
-    // with an explicit interface with a procedure with an implicit interface
-    msg = "Procedure %s with explicit interface may not be associated with"
-          " procedure designator '%s' with implicit interface"_err_en_US;
+    // with an explicit interface with a procedure whose characteristics don't
+    // match.  That's the case if the target procedure has an implicit
+    // interface.  But this case is allowed by several other compilers.
   } else if (!lhsProcedure->HasExplicitInterface() &&
       rhsProcedure->HasExplicitInterface()) {
+    // OK if the target can be called via an implicit interface
     if (!rhsProcedure->CanBeCalledViaImplicitInterface()) {
       msg = "Procedure %s with implicit interface may not be associated "
             "with procedure designator '%s' with explicit interface that "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119404.407376.patch
Type: text/x-patch
Size: 3363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220210/85e37919/attachment.bin>


More information about the llvm-commits mailing list