From d51aa9ddb499444b7f912975d63627b33fe6cdf5 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Tue, 4 Mar 2025 14:24:58 -0800 Subject: [PATCH] [flang] Enforce C955 on DEALLOCATE Constraint C955 in F'2023 prohibits an allocate-object from being coindexed. We catch this on ALLOCATE statements but missed it on DEALLOCATE. --- flang/lib/Semantics/check-deallocate.cpp | 3 +++ flang/test/Semantics/deallocate05.f90 | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/flang/lib/Semantics/check-deallocate.cpp b/flang/lib/Semantics/check-deallocate.cpp index 7cac1c413b643..3bcd4d87b0906 100644 --- a/flang/lib/Semantics/check-deallocate.cpp +++ b/flang/lib/Semantics/check-deallocate.cpp @@ -89,6 +89,9 @@ void DeallocateChecker::Leave(const parser::DeallocateStmt &deallocateStmt) { "Object in DEALLOCATE statement is not deallocatable"_err_en_US) .Attach(std::move( whyNot->set_severity(parser::Severity::Because))); + } else if (evaluate::ExtractCoarrayRef(*expr)) { // F'2023 C955 + context_.Say(source, + "Component in DEALLOCATE statement may not be coindexed"_err_en_US); } } }, diff --git a/flang/test/Semantics/deallocate05.f90 b/flang/test/Semantics/deallocate05.f90 index bdc6998094064..382957f1005cc 100644 --- a/flang/test/Semantics/deallocate05.f90 +++ b/flang/test/Semantics/deallocate05.f90 @@ -27,6 +27,11 @@ Program deallocatetest Character(256) :: ee Procedure(Real) :: prp +type at + real, allocatable :: a +end type +type(at) :: c[*] + Allocate(rp) Deallocate(rp) @@ -67,4 +72,7 @@ Program deallocatetest !ERROR: ERRMSG may not be duplicated in a DEALLOCATE statement Deallocate(x, stat=s, errmsg=ee, errmsg=ee) +!ERROR: Component in DEALLOCATE statement may not be coindexed +deallocate(c[1]%a) + End Program deallocatetest