[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
Mon Apr 20 04:08:44 PDT 2026
https://github.com/JDPailleux created https://github.com/llvm/llvm-project/pull/192940
It appears that variables of type `EVENT_TYPE`, `LOCK_TYPE`, and `NOTIFY_TYPE` are not allowed in the DEALLOCATE statement (but allowed in ALLOCATE).
The standard does not specify that this type of variable cannot be ALLOCATABLE and/or cannot be called within a DEALLOCATE
>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] [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
More information about the flang-commits
mailing list