[flang-commits] [flang] 8ddedbf - [flang] Assume unknown target of procedure pointer assignment is a pr… (#66232)

via flang-commits flang-commits at lists.llvm.org
Wed Sep 13 15:47:36 PDT 2023


Author: Peter Klausler
Date: 2023-09-13T15:47:31-07:00
New Revision: 8ddedbf2f8788903ec1a048830d3959138583e6b

URL: https://github.com/llvm/llvm-project/commit/8ddedbf2f8788903ec1a048830d3959138583e6b
DIFF: https://github.com/llvm/llvm-project/commit/8ddedbf2f8788903ec1a048830d3959138583e6b.diff

LOG: [flang] Assume unknown target of procedure pointer assignment is a pr… (#66232)

…ocedure

When an previously unknown name appears as the target of an assignment
to a known procedure pointer, create an external symbol for it rather
than an implicitly-typed object symbol.

Added: 
    flang/test/Semantics/symbol31.f90

Modified: 
    flang/lib/Semantics/resolve-names.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 865c198424696a9..29cd107186fb5f0 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -8108,6 +8108,15 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
         return false;
       }
     }
+    if (IsProcedurePointer(parser::GetLastName(dataRef).symbol) &&
+        !FindSymbol(*name)) {
+      // Unknown target of procedure pointer must be an external procedure
+      Symbol &symbol{MakeSymbol(
+          context().globalScope(), name->source, Attrs{Attr::EXTERNAL})};
+      Resolve(*name, symbol);
+      ConvertToProcEntity(symbol);
+      return false;
+    }
   }
   Walk(expr);
   return false;

diff  --git a/flang/test/Semantics/symbol31.f90 b/flang/test/Semantics/symbol31.f90
new file mode 100644
index 000000000000000..c8016cf9ec71b9b
--- /dev/null
+++ b/flang/test/Semantics/symbol31.f90
@@ -0,0 +1,7 @@
+! RUN: %python %S/test_symbols.py %s %flang_fc1
+ !DEF: /MainProgram1/pptr EXTERNAL, POINTER ProcEntity
+ procedure(), pointer :: pptr
+ !REF: /MainProgram1/pptr
+ !DEF: /mustbeexternal EXTERNAL ProcEntity
+ pptr => mustbeexternal
+end program


        


More information about the flang-commits mailing list