[flang-commits] [PATCH] D136905: [flang] Catch inconsistent function/subroutine usage of procedure pointer components

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Oct 27 17:35:06 PDT 2022


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

When a derived type has a procedure pointer component with no interface,
we can't do a lot of checking on its call sites, but we can at least require
that the same procedure pointer component be used consistently as either
a function or as a subroutine, but not both.


https://reviews.llvm.org/D136905

Files:
  flang/lib/Semantics/resolve-names.cpp
  flang/test/Semantics/resolve09.f90


Index: flang/test/Semantics/resolve09.f90
===================================================================
--- flang/test/Semantics/resolve09.f90
+++ flang/test/Semantics/resolve09.f90
@@ -113,3 +113,16 @@
 function b8()
   b8 = 0.0
 end
+
+subroutine s9
+  type t
+    procedure(), nopass, pointer :: p1, p2
+  end type
+  type(t) x
+  print *, x%p1()
+  call x%p2
+  !ERROR: Cannot call function 'p1' like a subroutine
+  call x%p1
+  !ERROR: Cannot call subroutine 'p2' like a function
+  print *, x%p2()
+end subroutine
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -6933,7 +6933,15 @@
   common::visit(
       common::visitors{
           [&](const parser::Name &x) { HandleProcedureName(procFlag, x); },
-          [&](const parser::ProcComponentRef &x) { Walk(x); },
+          [&](const parser::ProcComponentRef &x) {
+            Walk(x);
+            const parser::Name &name{x.v.thing.component};
+            if (Symbol * symbol{name.symbol}) {
+              if (IsProcedure(*symbol)) {
+                SetProcFlag(name, *symbol, procFlag);
+              }
+            }
+          },
       },
       std::get<parser::ProcedureDesignator>(call.t).u);
   Walk(std::get<std::list<parser::ActualArgSpec>>(call.t));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136905.471340.patch
Type: text/x-patch
Size: 1386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221028/f6fc4b9d/attachment-0001.bin>


More information about the flang-commits mailing list