[flang-commits] [flang] [flang] Check for ultimate ALLOCATABLE component in LOCAL_INIT() (PR #145800)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Mon Jun 30 05:47:55 PDT 2025
https://github.com/eugeneepshteyn updated https://github.com/llvm/llvm-project/pull/145800
>From 0b88735d49a7837d117ccaaa90469beed4a5eaf2 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Wed, 25 Jun 2025 17:35:49 -0400
Subject: [PATCH 1/7] [flang] Check for ultimate ALLOCATABLE component in
LOCAL_INIT()
Fortran 2023 constraint C1130 disallows variables of derived type with
ultimate allocatable component to appear in LOCAL_INIT().
---
flang/lib/Semantics/resolve-names.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 9e465f8ff3e1e..8c1a7d29b60ec 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 % locality-spec"_err_en_US,
+ specName);
+ }
+ }
}
if (symbol.attrs().test(Attr::ASYNCHRONOUS) && isReduce) { // F'2023 C1131
SayWithDecl(name, symbol,
>From 6ed9505ce997462a035efac70214c5a008e04400 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Wed, 25 Jun 2025 18:09:28 -0400
Subject: [PATCH 2/7] Fixed format string issue
---
flang/lib/Semantics/resolve-names.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 8c1a7d29b60ec..29ae915add64c 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7281,7 +7281,7 @@ bool DeclarationVisitor::PassesLocalityChecks(
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 % locality-spec"_err_en_US,
+ "Derived type variable '%s' with ultimate ALLOCATABLE component not allowed in a %s locality-spec"_err_en_US,
specName);
}
}
>From bec4c181e2396b6e533cf33989f26577b84756ba Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Wed, 25 Jun 2025 18:25:45 -0400
Subject: [PATCH 3/7] Unit test
---
flang/test/Semantics/resolve55.f90 | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
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
>From 8051a1b92b2fc2af90df26a85483d25e7b8ed163 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Wed, 25 Jun 2025 18:28:39 -0400
Subject: [PATCH 4/7] clang-format
---
flang/lib/Semantics/resolve-names.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 29ae915add64c..e17c99c1d510c 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7281,8 +7281,8 @@ bool DeclarationVisitor::PassesLocalityChecks(
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);
+ "Derived type variable '%s' with ultimate ALLOCATABLE component not allowed in a %s locality-spec"_err_en_US,
+ specName);
}
}
}
>From 4ab186300afc28355e93fb30c94ffcaae99405b6 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Wed, 25 Jun 2025 18:31:39 -0400
Subject: [PATCH 5/7] Added missing 'return'
---
flang/lib/Semantics/resolve-names.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index e17c99c1d510c..351f6fb2b6995 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7283,6 +7283,7 @@ bool DeclarationVisitor::PassesLocalityChecks(
SayWithDecl(name, symbol,
"Derived type variable '%s' with ultimate ALLOCATABLE component not allowed in a %s locality-spec"_err_en_US,
specName);
+ return false;
}
}
}
>From 06f1671b28a84ebbf1af37964c2b38b360eb7d13 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Wed, 25 Jun 2025 18:39:37 -0400
Subject: [PATCH 6/7] github code formatter was somehow more stringent than
'git clang-format'
---
flang/lib/Semantics/resolve-names.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 351f6fb2b6995..4d22442a22a64 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7278,7 +7278,7 @@ bool DeclarationVisitor::PassesLocalityChecks(
specName);
return false;
}
- if (const DerivedTypeSpec * derived{type->AsDerived()}) { // F'2023 C1130
+ 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,
>From 170e463e60b03757517c751b6fd2777c042c79a9 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Wed, 25 Jun 2025 19:06:31 -0400
Subject: [PATCH 7/7] Code review feedback: display the name of ultimate
ALLOCATABLE component
---
flang/lib/Semantics/resolve-names.cpp | 4 ++--
flang/test/Semantics/resolve55.f90 | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 4d22442a22a64..6a464e7ad8d24 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -7281,8 +7281,8 @@ bool DeclarationVisitor::PassesLocalityChecks(
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);
+ "Derived type variable '%s' with ultimate ALLOCATABLE component '%s' not allowed in a %s locality-spec"_err_en_US,
+ bad.BuildResultDesignatorName(), specName);
return false;
}
}
diff --git a/flang/test/Semantics/resolve55.f90 b/flang/test/Semantics/resolve55.f90
index 398058b066be8..908fda8a83e15 100644
--- a/flang/test/Semantics/resolve55.f90
+++ b/flang/test/Semantics/resolve55.f90
@@ -109,7 +109,7 @@ subroutine s9()
integer sum
sum = 0
-!ERROR: Derived type variable 'v' with ultimate ALLOCATABLE component not allowed in a LOCAL_INIT locality-spec
+!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
More information about the flang-commits
mailing list