Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 13, 2023

Conversation

klausler
Copy link
Contributor

…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.

…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.
@klausler klausler requested a review from a team as a code owner September 13, 2023 16:34
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 13, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 13, 2023

@llvm/pr-subscribers-flang-semantics

Changes …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.

Full diff: https://github.com/llvm/llvm-project/pull/66232.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+9)
  • (added) flang/test/Semantics/symbol31.f90 (+7)
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

@klausler klausler merged commit 8ddedbf into llvm:main Sep 13, 2023
4 checks passed
@klausler klausler deleted the c03_138 branch September 13, 2023 22:47
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
llvm#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.
klausler added a commit to klausler/llvm-project that referenced this pull request Oct 30, 2023
A recent fix (llvm#66232)
to interpret a hitherto unknown name whose first appearance is as
the target of a procedure pointer initializer as an external
procedure has led to some inapproprite warning messages if the
name is later defined as an external subroutine ("X was already
declared as an external").

Ensure that the EXTERNAL attribute is correctly noted as being
implicit, and that it's okay that neither the Subroutine nor Function
flag has yet been set for the implicit external.
klausler added a commit that referenced this pull request Oct 31, 2023
A recent fix (#66232) to
interpret a hitherto unknown name whose first appearance is as the
target of a procedure pointer initializer as an external procedure has
led to some inapproprite warning messages if the name is later defined
as an external subroutine ("X was already declared as an external").

Ensure that the EXTERNAL attribute is correctly noted as being implicit,
and that it's okay that neither the Subroutine nor Function flag has yet
been set for the implicit external.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants