Skip to content

Conversation

@klausler
Copy link
Contributor

A function result that is a procedure must be a procedure pointer.

A function result that is a procedure must be a procedure pointer.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Oct 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

A function result that is a procedure must be a procedure pointer.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-declarations.cpp (+4)
  • (added) flang/test/Semantics/func-proc-result.f90 (+18)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 31e246cf0ab03..7de29fc120851 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -472,6 +472,10 @@ void CheckHelper::Check(const Symbol &symbol) {
       messages_.Say(
           "A function result may not also be a named constant"_err_en_US);
     }
+    if (!IsProcedurePointer(symbol) && IsProcedure(symbol)) {
+      messages_.Say(
+          "A function result may not be a procedure unless it is a procedure pointer"_err_en_US);
+    }
   }
   if (IsAutomatic(symbol)) {
     if (const Symbol * common{FindCommonBlockContaining(symbol)}) {
diff --git a/flang/test/Semantics/func-proc-result.f90 b/flang/test/Semantics/func-proc-result.f90
new file mode 100644
index 0000000000000..5bf8ac9c4ddea
--- /dev/null
+++ b/flang/test/Semantics/func-proc-result.f90
@@ -0,0 +1,18 @@
+!RUN: %python %S/test_errors.py %s %flang_fc1
+
+function good() result(pptr)
+  procedure(), pointer :: pptr
+  external whatever
+  pptr => whatever
+end
+
+function bad1() result(res1)
+  !ERROR: A function result may not be a procedure unless it is a procedure pointer
+  procedure() res1
+end
+
+!ERROR: Procedure 'res2' is referenced before being sufficiently defined in a context where it must be so
+function bad2() result(res2)
+  !ERROR: EXTERNAL attribute not allowed on 'res2'
+  external res2
+end

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@klausler klausler merged commit 1e237b1 into llvm:main Oct 24, 2025
13 checks passed
@klausler klausler deleted the func-proc-result branch October 24, 2025 19:14
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
)

A function result that is a procedure must be a procedure pointer.
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
)

A function result that is a procedure must be a procedure pointer.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
)

A function result that is a procedure must be a procedure pointer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants