[flang-commits] [PATCH] D155963: [flang] Support implicit global external as procedure pointer target

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jul 21 08:17:15 PDT 2023


klausler created this revision.
klausler added a reviewer: clementval.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

A name that has been used to reference an undeclared global external
procedure should be accepted as the target of a procedure pointer
assignment statement.

Fixes llvm-test-suite/Fortran/gfortran/regression/proc_ptr_45.f90.


https://reviews.llvm.org/D155963

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


Index: flang/test/Semantics/assign09.f90
===================================================================
--- flang/test/Semantics/assign09.f90
+++ flang/test/Semantics/assign09.f90
@@ -41,6 +41,10 @@
   !ERROR: Actual procedure argument has interface incompatible with dummy argument 'p=': incompatible dummy argument #1: incompatible dummy data object types: REAL(4) vs INTEGER(4)
   call sub3(sqrt)
 
+  print *, implicitExtFunc()
+  call implicitExtSubr
+  noInterfaceProcPtr => implicitExtFunc ! ok
+  noInterfaceProcPtr => implicitExtSubr ! ok
   noInterfaceProcPtr => noInterfaceExternal ! ok
   realToRealProcPtr => noInterfaceExternal ! ok
   intToRealProcPtr => noInterfaceExternal !ok
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -7519,8 +7519,9 @@
                    currScope().context().GetPPCBuiltinsScope()) {
       // Check if it is a builtin from the predefined module
       symbol = FindSymbol(*ppcBuiltinScope, name);
-      if (!symbol)
+      if (!symbol) {
         symbol = &MakeSymbol(context().globalScope(), name.source, Attrs{});
+      }
     } else {
       symbol = &MakeSymbol(context().globalScope(), name.source, Attrs{});
     }
@@ -8030,6 +8031,15 @@
       }
       return false;
     }
+    // Can also reference a global external procedure here
+    if (auto it{context().globalScope().find(name->source)};
+        it != context().globalScope().end()) {
+      Symbol &global{*it->second};
+      if (IsProcedure(global)) {
+        Resolve(*name, global);
+        return false;
+      }
+    }
   }
   Walk(expr);
   return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155963.542927.patch
Type: text/x-patch
Size: 1734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230721/3d08135f/attachment-0001.bin>


More information about the flang-commits mailing list