[flang] [llvm] [Flang] Adding lowering for the allocation and deallocation of coarrays (PR #182110)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 18 14:05:18 PST 2026


================
@@ -9,11 +9,43 @@
 #include "flang/Optimizer/Dialect/MIF/MIFOps.h"
 #include "flang/Optimizer/Builder/Todo.h"
 #include "flang/Optimizer/Dialect/FIRAttr.h"
+#include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
 #include "flang/Optimizer/Dialect/MIF/MIFDialect.h"
+#include "flang/Optimizer/HLFIR/HLFIROps.h"
 #include "mlir/IR/Matchers.h"
 #include "mlir/IR/PatternMatch.h"
 #include "llvm/ADT/SmallVector.h"
+#include <tuple>
+
+// Function used to check if a type has POINTER or ALLOCATABLE component.
+// Currently an allocation of coarray with this kind of component are not yet
+// supported.
+static bool hasAllocatableOrPointerComponent(mlir::Type type) {
+  type = fir::unwrapPassByRefType(type);
+  if (fir::isa_box_type(type))
+    return hasAllocatableOrPointerComponent(type);
+  if (auto recType = mlir::dyn_cast<fir::RecordType>(type)) {
+    for (auto field : recType.getTypeList()) {
+      mlir::Type fieldType = fir::unwrapPassByRefType(field.second);
+      if (mlir::isa<fir::PointerType>(fieldType))
+        return true;
+      if (mlir::isa<fir::HeapType>(fieldType))
+        return true;
+      if (auto fieldRecType = mlir::dyn_cast<fir::RecordType>(fieldType))
+        return hasAllocatableOrPointerComponent(fieldRecType);
+      if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(fieldType)) {
+        if (seqTy.hasUnknownShape() || seqTy.hasDynamicExtents())
+          return true;
----------------
tmjbios wrote:

Why is a sequence of `getShape().empty()` here considered to have a Pointer or Allocatable component?

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


More information about the llvm-commits mailing list