Skip to content

[flang] Check for ultimate ALLOCATABLE component in LOCAL_INIT() #145800

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

eugeneepshteyn
Copy link
Contributor

Fortran 2023 constraint C1130 disallows variables of derived type with ultimate allocatable component to appear in LOCAL_INIT().

Fortran 2023 constraint C1130 disallows variables of derived type with
ultimate allocatable component to appear in LOCAL_INIT().
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jun 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 25, 2025

@llvm/pr-subscribers-flang-semantics

Author: Eugene Epshteyn (eugeneepshteyn)

Changes

Fortran 2023 constraint C1130 disallows variables of derived type with ultimate allocatable component to appear in LOCAL_INIT().


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+7)
  • (modified) flang/test/Semantics/resolve55.f90 (+20)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 9e465f8ff3e1e..e17c99c1d510c 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7278,6 +7278,13 @@ bool DeclarationVisitor::PassesLocalityChecks(
           specName);
       return false;
     }
+    if (const DerivedTypeSpec * derived{type->AsDerived()}) { // F'2023 C1130
+      if (auto bad{FindAllocatableUltimateComponent(*derived)}) {
+        SayWithDecl(name, symbol,
+            "Derived type variable '%s' with ultimate ALLOCATABLE component not allowed in a %s locality-spec"_err_en_US,
+            specName);
+      }
+    }
   }
   if (symbol.attrs().test(Attr::ASYNCHRONOUS) && isReduce) { // F'2023 C1131
     SayWithDecl(name, symbol,
diff --git a/flang/test/Semantics/resolve55.f90 b/flang/test/Semantics/resolve55.f90
index 5f7a3044e834c..398058b066be8 100644
--- a/flang/test/Semantics/resolve55.f90
+++ b/flang/test/Semantics/resolve55.f90
@@ -94,3 +94,23 @@ subroutine s8(arg)
   do concurrent(i=1:5) local(arg)
   end do
 end subroutine s8
+
+subroutine s9()
+  type l3
+    integer, allocatable :: a
+  end type
+  type l2
+    type(l3) :: l2_3
+  end type
+  type l1
+    type(l2) :: l1_2
+  end type
+  type(l1) :: v
+  integer sum
+
+  sum = 0
+!ERROR: Derived type variable 'v' with ultimate ALLOCATABLE component not allowed in a LOCAL_INIT locality-spec
+  do concurrent (i = 1:10) local_init(v)
+    sum = sum + i
+  end do
+end subroutine s9

Copy link

github-actions bot commented Jun 25, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -7278,6 +7278,14 @@ bool DeclarationVisitor::PassesLocalityChecks(
specName);
return false;
}
if (const DerivedTypeSpec *derived{type->AsDerived()}) { // F'2023 C1130
if (auto bad{FindAllocatableUltimateComponent(*derived)}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The variable bad is not used, but it should be; you can get the name of the offending component from it and include it in the message, as is usually done in other situations that use the component iterators.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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.

3 participants