[flang-commits] [flang] [flang][acc] remap no_create array sections (PR #178660)

via flang-commits flang-commits at lists.llvm.org
Tue Feb 3 01:35:36 PST 2026


https://github.com/jeanPerier updated https://github.com/llvm/llvm-project/pull/178660

>From f0752d67d4319b8f5c9dcaeea6200ca9b1fcc3a6 Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Wed, 28 Jan 2026 07:22:02 -0800
Subject: [PATCH] [flang][acc] remap no_create array sections

---
 flang/lib/Lower/OpenACC.cpp                   |  9 +-------
 .../OpenACC/acc-no-create-array-section.f90   | 21 +++++++++++++++++++
 2 files changed, 22 insertions(+), 8 deletions(-)
 create mode 100644 flang/test/Lower/OpenACC/acc-no-create-array-section.f90

diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 183f9e717532a..133cc973897af 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -775,16 +775,9 @@ genDataOperandOperations(const Fortran::parser::AccObjectList &objectList,
       if (auto *defOp = op.getVar().getDefiningOp())
         addDeclareAttr(builder, defOp, dataClause);
 
-    // TODO: no_create remapping could currently cause segfaults because of the
-    // fir.box_addr that may be inserted in the remapping in the region.
-    // This is an issue if the variable is not mapped (which is OK if its
-    // accesses are not reached inside the construct).
-    bool isNoCreateWithBounds =
-        std::is_same_v<Op, mlir::acc::NoCreateOp> && !bounds.empty();
-
     // Track the symbol and its corresponding mlir::Value if requested so that
     // accesses inside regions can be remapped.
-    if (dataMap && !isNoCreateWithBounds) {
+    if (dataMap) {
       if (componentRef)
         dataMap->emplaceComponent(op.getAccVar(), std::move(*componentRef),
                                   baseAddr);
diff --git a/flang/test/Lower/OpenACC/acc-no-create-array-section.f90 b/flang/test/Lower/OpenACC/acc-no-create-array-section.f90
new file mode 100644
index 0000000000000..3097eccc8cbee
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-no-create-array-section.f90
@@ -0,0 +1,21 @@
+! This test checks lowering of OpenACC no_create with an array section.
+
+! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
+
+subroutine foo(n)
+  real :: a(n)
+  !$acc parallel no_create(a(11:20))
+    call bar(a)
+  !$acc end parallel
+end subroutine
+! CHECK-LABEL:   func.func @_QPfoo(
+! CHECK:           %[[SHAPE_0:.*]] = fir.shape
+! CHECK:           %[[BOUNDS_0:.*]] = acc.bounds
+! CHECK:           %[[NOCREATE_0:.*]] = acc.nocreate var(%{{.*}} : !fir.box<!fir.array<?xf32>>) bounds(%[[BOUNDS_0]]) -> !fir.box<!fir.array<?xf32>> {name = "a(11:20)"}
+! CHECK:           acc.parallel dataOperands(%[[NOCREATE_0]] : !fir.box<!fir.array<?xf32>>) {
+! CHECK:             %[[BOX_ADDR_0:.*]] = fir.box_addr %[[NOCREATE_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
+! CHECK:             %[[DECLARE_2:.*]]:2 = hlfir.declare %[[BOX_ADDR_0]](%[[SHAPE_0]]) {uniq_name = "_QFfooEa"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)
+! CHECK:             fir.call @_QPbar(%[[DECLARE_2]]#1) fastmath<contract> : (!fir.ref<!fir.array<?xf32>>) -> ()
+! CHECK:             acc.yield
+! CHECK:           }
+! CHECK:           acc.delete accVar(%[[NOCREATE_0]] : !fir.box<!fir.array<?xf32>>) bounds(%[[BOUNDS_0]]) {dataClause = #acc<data_clause acc_no_create>, name = "a(11:20)"}



More information about the flang-commits mailing list