[flang-commits] [flang] [Flang][Semantics] Allow EVENT_TYPE, LOCK_TYPE and NOTIFY TYPE to be deallocate (PR #192940)
Jean-Didier PAILLEUX via flang-commits
flang-commits at lists.llvm.org
Tue Apr 21 02:04:23 PDT 2026
https://github.com/JDPailleux updated https://github.com/llvm/llvm-project/pull/192940
>From 0459013eaa1d45ded5aac03c59f57699bd5a1e44 Mon Sep 17 00:00:00 2001
From: Jean-Didier Pailleux <jean-didier.pailleux at sipearl.com>
Date: Fri, 17 Apr 2026 14:36:32 +0200
Subject: [PATCH 1/3] [Flang][Semantics] Allow EVENT_TYPE, LOCK_TYPE and NOTIFY
TYPE to be deallocate
---
flang/lib/Semantics/check-deallocate.cpp | 4 +-
flang/test/Semantics/deallocate08.f90 | 55 ++++++++++++++++++++++++
2 files changed, 57 insertions(+), 2 deletions(-)
create mode 100644 flang/test/Semantics/deallocate08.f90
diff --git a/flang/lib/Semantics/check-deallocate.cpp b/flang/lib/Semantics/check-deallocate.cpp
index 729e92aefc04c..6ba4571d83061 100644
--- a/flang/lib/Semantics/check-deallocate.cpp
+++ b/flang/lib/Semantics/check-deallocate.cpp
@@ -84,7 +84,7 @@ void DeallocateChecker::Leave(const parser::DeallocateStmt &deallocateStmt) {
whyNot->set_severity(parser::Severity::Because)));
} else if (auto whyNot{
WhyNotDefinable(source, context_.FindScope(source),
- DefinabilityFlags{}, *symbol)}) {
+ DefinabilityFlags{DefinabilityFlag::AllowEventLockOrNotifyType}, *symbol)}) {
// Catch problems with non-definability of the dynamic object
context_
.Say(source,
@@ -119,7 +119,7 @@ void DeallocateChecker::Leave(const parser::DeallocateStmt &deallocateStmt) {
.Attach(std::move(
whyNot->set_severity(parser::Severity::Because)));
} else if (auto whyNot{WhyNotDefinable(source,
- context_.FindScope(source), DefinabilityFlags{},
+ context_.FindScope(source), DefinabilityFlags{DefinabilityFlag::AllowEventLockOrNotifyType},
*expr)}) {
context_
.Say(source,
diff --git a/flang/test/Semantics/deallocate08.f90 b/flang/test/Semantics/deallocate08.f90
new file mode 100644
index 0000000000000..cf5a1346ee719
--- /dev/null
+++ b/flang/test/Semantics/deallocate08.f90
@@ -0,0 +1,55 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Check there are no semantic errors in DEALLOCATE statements with EVENT_TYPE and LOCK_TYPE.
+
+! CHECK-NOT: Object in DEALLOCATE statement is not deallocatable
+
+module not_iso_fortran_env
+ type event_type
+ end type
+ type lock_type
+ end type
+end module
+
+subroutine deallocate_lock_event_type()
+ use iso_fortran_env
+
+ type oktype1
+ type(event_type), pointer :: event
+ type(lock_type), pointer :: lock
+ end type
+
+ type oktype5
+ type(event_type), allocatable :: event
+ end type
+
+ type oktype2
+ type(event_type) :: event
+ end type
+
+ type oktype3
+ type(lock_type), allocatable :: lock
+ end type
+
+ type oktype4
+ type(lock_type) :: lock
+ end type
+
+ ! Variable with event_type or lock_type have to be coarrays
+ ! see C1604 and 1608.
+ type(oktype1), allocatable :: okt1[:]
+ type(oktype2), allocatable :: okt2[:]
+ type(oktype3), allocatable :: okt3[:]
+ type(oktype5), allocatable :: okt5[:]
+ class(oktype4), allocatable :: okt4[:]
+ type(event_type), allocatable :: event[:]
+ type(lock_type), allocatable :: lock(:)[:]
+
+
+ deallocate(okt1)
+ deallocate(okt2)
+ deallocate(okt3)
+ deallocate(okt4)
+ deallocate(okt5)
+ deallocate(lock)
+ deallocate(event)
+end subroutine
>From 4d6dbc87e95f4f62a9e5d092a1a518299f611050 Mon Sep 17 00:00:00 2001
From: Jean-Didier Pailleux <jean-didier.pailleux at sipearl.com>
Date: Mon, 20 Apr 2026 13:28:14 +0200
Subject: [PATCH 2/3] Fix clang-format
---
flang/lib/Semantics/check-deallocate.cpp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/flang/lib/Semantics/check-deallocate.cpp b/flang/lib/Semantics/check-deallocate.cpp
index 6ba4571d83061..ee14e966b4a67 100644
--- a/flang/lib/Semantics/check-deallocate.cpp
+++ b/flang/lib/Semantics/check-deallocate.cpp
@@ -82,9 +82,11 @@ void DeallocateChecker::Leave(const parser::DeallocateStmt &deallocateStmt) {
"Name in DEALLOCATE statement is not definable"_err_en_US)
.Attach(std::move(
whyNot->set_severity(parser::Severity::Because)));
- } else if (auto whyNot{
- WhyNotDefinable(source, context_.FindScope(source),
- DefinabilityFlags{DefinabilityFlag::AllowEventLockOrNotifyType}, *symbol)}) {
+ } else if (auto whyNot{WhyNotDefinable(source,
+ context_.FindScope(source),
+ DefinabilityFlags{
+ DefinabilityFlag::AllowEventLockOrNotifyType},
+ *symbol)}) {
// Catch problems with non-definability of the dynamic object
context_
.Say(source,
@@ -119,7 +121,9 @@ void DeallocateChecker::Leave(const parser::DeallocateStmt &deallocateStmt) {
.Attach(std::move(
whyNot->set_severity(parser::Severity::Because)));
} else if (auto whyNot{WhyNotDefinable(source,
- context_.FindScope(source), DefinabilityFlags{DefinabilityFlag::AllowEventLockOrNotifyType},
+ context_.FindScope(source),
+ DefinabilityFlags{DefinabilityFlag::
+ AllowEventLockOrNotifyType},
*expr)}) {
context_
.Say(source,
>From 9df53e65b72d67eee16c715fce64cb41a7469a4a Mon Sep 17 00:00:00 2001
From: Jean-Didier Pailleux <jean-didier.pailleux at sipearl.com>
Date: Tue, 21 Apr 2026 11:04:04 +0200
Subject: [PATCH 3/3] Updating test
---
flang/test/Semantics/deallocate08.f90 | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/flang/test/Semantics/deallocate08.f90 b/flang/test/Semantics/deallocate08.f90
index cf5a1346ee719..384be6c15b026 100644
--- a/flang/test/Semantics/deallocate08.f90
+++ b/flang/test/Semantics/deallocate08.f90
@@ -3,13 +3,6 @@
! CHECK-NOT: Object in DEALLOCATE statement is not deallocatable
-module not_iso_fortran_env
- type event_type
- end type
- type lock_type
- end type
-end module
-
subroutine deallocate_lock_event_type()
use iso_fortran_env
@@ -44,12 +37,13 @@ subroutine deallocate_lock_event_type()
type(event_type), allocatable :: event[:]
type(lock_type), allocatable :: lock(:)[:]
-
- deallocate(okt1)
- deallocate(okt2)
- deallocate(okt3)
- deallocate(okt4)
- deallocate(okt5)
- deallocate(lock)
- deallocate(event)
+ if (.false.) then
+ deallocate(okt1)
+ deallocate(okt2)
+ deallocate(okt3)
+ deallocate(okt4)
+ deallocate(okt5)
+ deallocate(lock)
+ deallocate(event)
+ endif
end subroutine
More information about the flang-commits
mailing list