[flang-commits] [flang] [Flang] Coarray allocation, update error for pointer component #193829 (PR #194651)
Jean-Didier PAILLEUX via flang-commits
flang-commits at lists.llvm.org
Thu Aug 6 04:20:39 PDT 2026
https://github.com/JDPailleux updated https://github.com/llvm/llvm-project/pull/194651
>From 04fa73ddfd1d83f6b3f58afc3d5b4a2c9d2b83f4 Mon Sep 17 00:00:00 2001
From: Jean-Didier Pailleux <jean-didier.pailleux at sipearl.com>
Date: Tue, 28 Apr 2026 16:55:32 +0200
Subject: [PATCH] [Flang] Coarray allocation, update error message for pointer
component #193829
---
flang/include/flang/Semantics/tools.h | 2 ++
flang/lib/Lower/ConvertVariable.cpp | 18 +++++++++++++++---
flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp | 6 +++---
flang/lib/Semantics/tools.cpp | 5 +++++
flang/test/Lower/MIF/coarray_allocation3.f90 | 3 ++-
5 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h
index b54204c8328d5..1b4e3d27f28f1 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -195,6 +195,8 @@ const Symbol *HasImpureFinal(
bool MayRequireFinalization(const DerivedTypeSpec &);
// Does this type have an allocatable direct component?
bool HasAllocatableDirectComponent(const DerivedTypeSpec &);
+// Does this type have a pointer direct component?
+bool HasPointerDirectComponent(const DerivedTypeSpec &);
// Does this type have any defined assignment at any level (or any polymorphic
// allocatable)?
bool MayHaveDefinedAssignment(const DerivedTypeSpec &);
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index 32b0863b4d57a..a808905850922 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -118,6 +118,15 @@ hasAllocatableDirectComponent(const Fortran::semantics::Symbol &sym) {
*derivedTypeSpec);
return false;
}
+// Does this variable have a pointer direct component?
+static bool hasPointerDirectComponent(const Fortran::semantics::Symbol &sym) {
+ if (sym.has<Fortran::semantics::ObjectEntityDetails>())
+ if (const Fortran::semantics::DeclTypeSpec *declTypeSpec = sym.GetType())
+ if (const Fortran::semantics::DerivedTypeSpec *derivedTypeSpec =
+ declTypeSpec->AsDerived())
+ return Fortran::semantics::HasPointerDirectComponent(*derivedTypeSpec);
+ return false;
+}
//===----------------------------------------------------------------===//
// Global variables instantiation (not for alias and common)
//===----------------------------------------------------------------===//
@@ -675,9 +684,12 @@ static void instantiateGlobal(Fortran::lower::AbstractConverter &converter,
fir::GlobalOp global;
if (Fortran::evaluate::IsCoarray(sym)) {
- if (hasFinalization(sym) || hasAllocatableDirectComponent(sym))
- TODO(loc, "coarray: coarray with an allocatable direct component and/or "
- "requiring finalization");
+ if (hasFinalization(sym) || hasAllocatableDirectComponent(sym) ||
+ hasPointerDirectComponent(sym))
+ TODO(
+ loc,
+ "coarray: coarray with a pointer/allocatable direct component and/or "
+ "requiring finalization.");
const auto *details =
sym.detailsIf<Fortran::semantics::ObjectEntityDetails>();
if (details && details->init())
diff --git a/flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp b/flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp
index 2bafc33450392..223f7f44205f5 100644
--- a/flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp
+++ b/flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp
@@ -267,9 +267,9 @@ void mif::AllocCoarrayOp::build(mlir::OpBuilder &builder,
llvm::LogicalResult mif::AllocCoarrayOp::verify() {
if (hasAllocatableOrPointerComponent(getBox().getType()))
- TODO(getLoc(),
- "Derived type coarray with at least one ALLOCATABLE or POINTER "
- "component");
+ return emitOpError(
+ "not implemented: Derived type coarray with at least one ALLOCATABLE"
+ " or POINTER component");
fir::BoxType lcElemType =
mlir::dyn_cast<fir::BoxType>(getLcobounds().getType());
diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 92bd599fdab2f..64e76aa02fe6d 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -841,6 +841,11 @@ bool HasAllocatableDirectComponent(const DerivedTypeSpec &derived) {
return std::any_of(directs.begin(), directs.end(), IsAllocatable);
}
+bool HasPointerDirectComponent(const DerivedTypeSpec &derived) {
+ DirectComponentIterator directs{derived};
+ return std::any_of(directs.begin(), directs.end(), IsPointer);
+}
+
static bool MayHaveDefinedAssignment(
const DerivedTypeSpec &derived, std::set<const Scope *> &checked) {
if (const Scope *scope{derived.GetScope()};
diff --git a/flang/test/Lower/MIF/coarray_allocation3.f90 b/flang/test/Lower/MIF/coarray_allocation3.f90
index b4fc02baee064..0aad53428abd0 100644
--- a/flang/test/Lower/MIF/coarray_allocation3.f90
+++ b/flang/test/Lower/MIF/coarray_allocation3.f90
@@ -1,6 +1,6 @@
! RUN: not %flang_fc1 -emit-hlfir -fcoarray %s -o - 2>&1 | FileCheck %s
-!CHECK: not yet implemented: coarray: coarray with an allocatable direct component and/or requiring finalization
+!CHECK: not yet implemented: coarray: coarray with a pointer/allocatable direct component and/or requiring finalization.
module m_test
implicit none
@@ -8,6 +8,7 @@ module m_test
type :: test_type
integer :: id
real, allocatable :: arr(:)
+ real, pointer :: ptr
contains
final :: finalize_func
end type test_type
More information about the flang-commits
mailing list