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

Jean-Didier PAILLEUX via flang-commits flang-commits at lists.llvm.org
Thu Feb 19 04:47:32 PST 2026


================
@@ -0,0 +1,38 @@
+//===-- runtime/coarray.cpp -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Runtime/coarray.h"
+#include "flang-rt/runtime/descriptor.h"
+#include "flang-rt/runtime/type-info.h"
+
+namespace Fortran::runtime {
+
+extern "C" {
+RT_EXT_API_GROUP_BEGIN
+
+void RTDEF(ComputeLastUcobound)(
+    int num_images, const Descriptor &lcobounds, const Descriptor &ucobounds) {
+  int corank = ucobounds.GetDimension(0).Extent();
+  int64_t *lcobounds_ptr = (int64_t *)lcobounds.raw().base_addr;
+  int64_t *ucobounds_ptr = (int64_t *)ucobounds.raw().base_addr;
+  int64_t index = 1;
+  for (int i = 0; i < corank - 1; i++) {
+    index *= ucobounds_ptr[i] - lcobounds_ptr[i] + 1;
+  }
+  if (corank == 1)
+    ucobounds_ptr[0] = num_images - lcobounds_ptr[0] + 1;
----------------
JDPailleux wrote:

Sorry, I put the wrong calculation here!

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


More information about the flang-commits mailing list