[flang-commits] [flang] 93849a3 - [flang] Check for ultimate ALLOCATABLE component in LOCAL_INIT() (#145800)

via flang-commits flang-commits at lists.llvm.org
Mon Jun 30 12:49:10 PDT 2025


Author: Eugene Epshteyn
Date: 2025-06-30T15:49:07-04:00
New Revision: 93849a39c432827473ca6c676f1500da69b3aaa0

URL: https://github.com/llvm/llvm-project/commit/93849a39c432827473ca6c676f1500da69b3aaa0
DIFF: https://github.com/llvm/llvm-project/commit/93849a39c432827473ca6c676f1500da69b3aaa0.diff

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

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

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/resolve55.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 987824f0fcee8..d0336c9cb661d 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7278,6 +7278,14 @@ 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 '%s' not allowed in a %s locality-spec"_err_en_US,
+            bad.BuildResultDesignatorName(), specName);
+        return false;
+      }
+    }
   }
   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..908fda8a83e15 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 '%l1_2%l2_3%a' not allowed in a LOCAL_INIT locality-spec
+  do concurrent (i = 1:10) local_init(v)
+    sum = sum + i
+  end do
+end subroutine s9


        


More information about the flang-commits mailing list