[flang-commits] [PATCH] D139127: [flang] Document and warn about an extension

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Dec 1 10:17:34 PST 2022


klausler created this revision.
klausler added a reviewer: clementval.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.

Standard Fortran allows type-bound procedure bindings to only
be called, and disallows them from being used in other contexts
where a procedure name can be: as the target of a procedure pointer
assignment statement, and as an actual argument that corresponds
to a dummy procedure.  So long as the interfaces match, there's
no good reason for these uses to be errors, and there some obvious
use cases in polymorphic programming.  So emit portability warnings
rather than errors, and document this usage as an extension.


https://reviews.llvm.org/D139127

Files:
  flang/docs/Extensions.md
  flang/lib/Semantics/check-call.cpp
  flang/lib/Semantics/pointer-assignment.cpp
  flang/test/Semantics/bindings03.f90


Index: flang/test/Semantics/bindings03.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/bindings03.f90
@@ -0,0 +1,26 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror
+! Confirm a portability warning on use of a procedure binding apart from a call
+module m
+  type t
+   contains
+    procedure :: sub
+  end type
+ contains
+  subroutine sub(x)
+    class(t), intent(in) :: x
+  end subroutine
+end module
+
+program test
+  use m
+  procedure(sub), pointer :: p
+  type(t) x
+  !PORTABILITY: Procedure binding 'sub' used as target of a pointer assignment
+  p => x%sub
+  !PORTABILITY: Procedure binding 'sub' passed as an actual argument
+  call sub2(x%sub)
+ contains
+  subroutine sub2(s)
+    procedure(sub) s
+  end subroutine
+end
Index: flang/lib/Semantics/pointer-assignment.cpp
===================================================================
--- flang/lib/Semantics/pointer-assignment.cpp
+++ flang/lib/Semantics/pointer-assignment.cpp
@@ -307,6 +307,10 @@
             symbol->name());
         return false;
       }
+    } else if (symbol->has<ProcBindingDetails>()) {
+      evaluate::SayWithDeclaration(context_.messages(), *symbol,
+          "Procedure binding '%s' used as target of a pointer assignment"_port_en_US,
+          symbol->name());
     }
   }
   if (auto chars{Procedure::Characterize(d, context_)}) {
Index: flang/lib/Semantics/check-call.cpp
===================================================================
--- flang/lib/Semantics/check-call.cpp
+++ flang/lib/Semantics/check-call.cpp
@@ -596,6 +596,10 @@
               argProcSymbol->name());
           return;
         }
+      } else if (argProcSymbol->has<ProcBindingDetails>()) {
+        evaluate::SayWithDeclaration(messages, *argProcSymbol,
+            "Procedure binding '%s' passed as an actual argument"_port_en_US,
+            argProcSymbol->name());
       }
     }
     if (auto argChars{characteristics::DummyArgument::FromActual(
Index: flang/docs/Extensions.md
===================================================================
--- flang/docs/Extensions.md
+++ flang/docs/Extensions.md
@@ -240,6 +240,16 @@
 * The legacy extension intrinsic functions `IZEXT` and `JZEXT`
   are supported; `ZEXT` has different behavior with various older
   compilers, so it is not supported.
+* f18 doesn't impose a limit on the number of continuation lines
+  allowed for a single statement.
+* When a type-bound procedure declaration statement has neither interface
+  nor attributes, the "::" before the bindings is optional, even
+  if a binding has renaming with "=> proc".
+  The colons are not necessary for an unambiguous parse, C768
+  notwithstanding.
+* A type-bound procedure binding can be passed as an actual
+  argument corresponding to a dummy procedure and can be used as
+  the target of a procedure pointer assignment statement.
 
 ### Extensions supported when enabled by options
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139127.479346.patch
Type: text/x-patch
Size: 2972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221201/1a9868d9/attachment.bin>


More information about the flang-commits mailing list