Skip to content

Conversation

@klausler
Copy link
Contributor

…TENT

A dummy procedure pointer with no INTENT attribute may associate with an actual argument that is the result of a reference to a function that returns a procedure pointer, we think.

Fixes #126950.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Feb 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 25, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

…TENT

A dummy procedure pointer with no INTENT attribute may associate with an actual argument that is the result of a reference to a function that returns a procedure pointer, we think.

Fixes #126950.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-call.cpp (+1-1)
  • (modified) flang/test/Semantics/call09.f90 (+2-4)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index e396ece303103..4a421dcc75b7d 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1185,7 +1185,7 @@ static void CheckProcedureArg(evaluate::ActualArgument &arg,
               dummyName);
         }
       } else if (!(dummy.intent == common::Intent::Default &&
-                     IsNullProcedurePointer(*expr))) {
+                     IsProcedurePointer(*expr))) {
         // 15.5.2.9(5) -- dummy procedure POINTER
         // Interface compatibility has already been checked above
         messages.Say(
diff --git a/flang/test/Semantics/call09.f90 b/flang/test/Semantics/call09.f90
index b8583ba4a4907..79fbff14e8a1b 100644
--- a/flang/test/Semantics/call09.f90
+++ b/flang/test/Semantics/call09.f90
@@ -87,8 +87,7 @@ subroutine test1 ! 15.5.2.9(5)
     call s02(p) ! ok
     !ERROR: Actual procedure argument has interface incompatible with dummy argument 'p=': function results have distinct types: REAL(4) vs INTEGER(4)
     call s02(ip)
-    !ERROR: Actual argument associated with procedure pointer dummy argument 'p=' must be a pointer unless INTENT(IN)
-    call s02(procptr())
+    call s02(procptr()) ! believed to be ok
     call s02(null()) ! ok
     !ERROR: Actual argument associated with procedure pointer dummy argument 'p=' must be a pointer unless INTENT(IN)
     call s05(null())
@@ -99,8 +98,7 @@ subroutine test1 ! 15.5.2.9(5)
     call s02b(p) ! ok
     !ERROR: Actual argument function associated with procedure dummy argument 'p=' is not compatible: function results have distinct types: REAL(4) vs INTEGER(4)
     call s02b(ip)
-    !ERROR: Actual argument associated with procedure pointer dummy argument 'p=' must be a pointer unless INTENT(IN)
-    call s02b(procptr())
+    call s02b(procptr()) ! believed to be ok
     call s02b(null())
     !ERROR: Actual argument associated with procedure pointer dummy argument 'p=' must be a pointer unless INTENT(IN)
     call s02b(sin)

Copy link
Contributor

@DanielCChen DanielCChen left a comment

Choose a reason for hiding this comment

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

I added intent(inout) to the test case and got

./t4.f:12:16: error: Actual argument associated with procedure pointer dummy argument 'p=' must be a pointer unless INTENT(IN)
      call test1(genF1(1))
                 ^^^^^^^^

May be ... must be a pointer for INTENT(INOUT).
Just a nit.
Thanks for fixing it.

@klausler
Copy link
Contributor Author

I added intent(inout) to the test case and got

./t4.f:12:16: error: Actual argument associated with procedure pointer dummy argument 'p=' must be a pointer unless INTENT(IN)
      call test1(genF1(1))
                 ^^^^^^^^

May be ... must be a pointer for INTENT(INOUT). Just a nit. Thanks for fixing it.

No. INTENT(IN OUT) requires the actual argument to be definable.

@DanielCChen
Copy link
Contributor

DanielCChen commented Feb 26, 2025

I added the following in the issue, and it is the reason I was thinking of the message text change.

The standard does say the following for INTENT(OUT) and INTENT(INOUT)

Any actual argument that corresponds to such a dummy pointer shall
be a pointer variable or a procedure pointer that is not the result of a function reference.

So I think it should be the same for all non-definable actual argument, the check should be on the presence of those two intents rather than missing INTENT(IN).

…TENT

A dummy procedure pointer with no INTENT attribute may associate with
an actual argument that is the result of a reference to a function that
returns a procedure pointer, we think.

Fixes llvm#126950.
@klausler klausler merged commit 8b7a90b into llvm:main Feb 27, 2025
11 checks passed
@klausler klausler deleted the bug126950 branch February 27, 2025 22:31
cheezeburglar pushed a commit to cheezeburglar/llvm-project that referenced this pull request Feb 28, 2025
llvm#128771)

…TENT

A dummy procedure pointer with no INTENT attribute may associate with an
actual argument that is the result of a reference to a function that
returns a procedure pointer, we think.

Fixes llvm#126950.
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.

[Flang] Incorrect diagnostic on procedure pointer actual argument

5 participants