Skip to content

Conversation

@klausler
Copy link
Contributor

@klausler klausler commented Mar 4, 2025

Constraint C955 in F'2023 prohibits an allocate-object from being coindexed. We catch this on ALLOCATE statements but missed it 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.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Mar 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

Constraint C955 in F'2023 prohibits an allocate-object from being coindexed. We catch this on ALLOCATE statements but missed it on DEALLOCATE.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-deallocate.cpp (+3)
  • (modified) flang/test/Semantics/deallocate05.f90 (+8)
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

@klausler klausler merged commit 33b061f into llvm:main Mar 10, 2025
14 checks passed
@klausler klausler deleted the fix074 branch March 10, 2025 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants