[flang-commits] [flang] [Flang][Semantics] Allow EVENT_TYPE, LOCK_TYPE and NOTIFY TYPE to be deallocate (PR #192940)

via flang-commits flang-commits at lists.llvm.org
Mon Apr 20 04:09:15 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Jean-Didier PAILLEUX (JDPailleux)

<details>
<summary>Changes</summary>

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

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


2 Files Affected:

- (modified) flang/lib/Semantics/check-deallocate.cpp (+2-2) 
- (added) flang/test/Semantics/deallocate08.f90 (+55) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/192940


More information about the flang-commits mailing list