Skip to content

[flang] Fix type inheritance for statement function dummy arguments #93624

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

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

klausler
Copy link
Contributor

The code that used existing type declarations (if any) for the names being used as dummy arguments in a statement function definition would apply those types only if they came from EntityDetails symbols. This broke a case in which the type was being inherited from a Cray pointee.

Fixes #93484.

The code that used existing type declarations (if any) for the names
being used as dummy arguments in a statement function definition would
apply those types only if they came from EntityDetails symbols.
This broke a case in which the type was being inherited from a
Cray pointee.

Fixes llvm#93484.
@klausler klausler requested a review from psteinfeld May 28, 2024 23:45
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels May 28, 2024
@klausler klausler requested review from DanielCChen and removed request for psteinfeld May 28, 2024 23:45
@llvmbot
Copy link
Member

llvmbot commented May 28, 2024

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

The code that used existing type declarations (if any) for the names being used as dummy arguments in a statement function definition would apply those types only if they came from EntityDetails symbols. This broke a case in which the type was being inherited from a Cray pointee.

Fixes #93484.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+2-4)
  • (modified) flang/test/Semantics/stmt-func01.f90 (+8-2)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 68cfc8641b9b2..fd3d4daea0154 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3694,10 +3694,8 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
   for (const auto &dummyName : std::get<std::list<parser::Name>>(x.t)) {
     ObjectEntityDetails dummyDetails{true};
     if (auto *dummySymbol{FindInScope(currScope().parent(), dummyName)}) {
-      if (auto *d{dummySymbol->detailsIf<EntityDetails>()}) {
-        if (d->type()) {
-          dummyDetails.set_type(*d->type());
-        }
+      if (auto *d{dummySymbol->GetType()}) {
+        dummyDetails.set_type(*d);
       }
     }
     Symbol &dummy{MakeSymbol(dummyName, std::move(dummyDetails))};
diff --git a/flang/test/Semantics/stmt-func01.f90 b/flang/test/Semantics/stmt-func01.f90
index 3c9ffa565900a..83c31ded1d39b 100644
--- a/flang/test/Semantics/stmt-func01.f90
+++ b/flang/test/Semantics/stmt-func01.f90
@@ -37,7 +37,13 @@ pure integer function ifunc()
   !ERROR: Statement function 'sf10' may not reference another statement function 'sf11' that is defined later
   sf10(n) = sf11(n)
   sf11(n) = sf10(n) ! mutual recursion, caused crash
-  sf13 = 1.
+  integer(1) iarg1
+  !PORTABILITY: nonstandard usage: based POINTER
+  pointer(iarg1p, iarg1)
+  sf13(iarg1) = iarg1
+  ! executable part
+  print *, sf13(iarg1) ! ok
+  sf14 = 1.
  contains
   real function explicit(x,y)
     integer, intent(in) :: x
@@ -50,7 +56,7 @@ pure function arr()
   end function
   subroutine foo
     !PORTABILITY: An implicitly typed statement function should not appear when the same symbol is available in its host scope
-    sf13(x) = 2.*x
+    sf14(x) = 2.*x
   end subroutine
 end
 

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.

LGTM. All affected test cases are passing now.
Thanks for the quick fix!

@klausler klausler merged commit 74f4034 into llvm:main Jun 3, 2024
10 checks passed
@klausler klausler deleted the bug93484 branch June 3, 2024 20:26
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] CrayPointer: Incorrect error message when the argument of a statement function is also a CrayPointer pointee
3 participants