[flang-commits] [flang] [flang][acc] Avoid assert for assumed-size arrays without a descriptor (PR #205726)

via flang-commits flang-commits at lists.llvm.org
Wed Jun 24 23:11:23 PDT 2026


https://github.com/khaki3 updated https://github.com/llvm/llvm-project/pull/205726

>From 1b1a37ae34a146812271e437db895e4cba1babc3 Mon Sep 17 00:00:00 2001
From: Kazuaki Matsumura <kmatsumura at nvidia.com>
Date: Wed, 24 Jun 2026 17:02:07 -0700
Subject: [PATCH 1/2] [flang][acc] Avoid assert for assumed-size arrays without
 a descriptor

generateSeqTyAccBounds() asserted that any array reaching the
dynamic/unknown-shape branch must have a descriptor. Assumed-size dummy
arguments violate this: they have an unknown trailing extent and are
passed without a descriptor. The OpenACC implicit-data pass
(fillInBoundsForUnknownDimensions) would then abort when synthesizing
bounds for such an array.

Return empty bounds in that case instead of asserting. With no
descriptor and an unknown extent there are no recoverable bounds, so the
array is mapped without bounds, which is correct for presence-only
clauses such as no_create/present.
---
 .../Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
index da9114200a5f2..e0ab6b148f11b 100644
--- a/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
+++ b/flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
@@ -345,7 +345,9 @@ generateSeqTyAccBounds(fir::SequenceType seqType, mlir::Value var,
           firBuilder, loc, exv, info);
     }
 
-    assert(false && "array with unknown dimension expected to have descriptor");
+    // An assumed-size array (or other non-descriptor array with an unknown
+    // trailing extent) has no recoverable bounds here and is passed without a
+    // descriptor; map it without bounds rather than asserting.
     return {};
   }
 

>From a2efe0b674148c1d5bcb83d9cffeba307927f2fb Mon Sep 17 00:00:00 2001
From: Kazuaki Matsumura <kmatsumura at nvidia.com>
Date: Wed, 24 Jun 2026 23:11:12 -0700
Subject: [PATCH 2/2] [flang][acc] Add test for assumed-size array without a
 descriptor

Add a regression test exercising acc bounds generation for an
assumed-size array (unknown trailing extent) passed without a descriptor
whose clause operand is not produced by an [hl]fir.declare, so no shape
is recoverable. The bounds generator must produce no bounds.
---
 flang/test/Fir/OpenACC/openacc-mappable.fir | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/flang/test/Fir/OpenACC/openacc-mappable.fir b/flang/test/Fir/OpenACC/openacc-mappable.fir
index 91a83915a0900..900ba2886c67e 100644
--- a/flang/test/Fir/OpenACC/openacc-mappable.fir
+++ b/flang/test/Fir/OpenACC/openacc-mappable.fir
@@ -141,4 +141,19 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<f16 = dense<16> : vector<2xi64>,
   // CHECK: fir.result %[[ZERO]], %[[MINUSONE]], %[[ZERO]], %[[ZERO]], %[[ZERO]] : index, index, index, index, index
   // CHECK: }
   // CHECK: Upper bound: %[[IF]]:5 = fir.if %[[PRESENT]] -> (index, index, index, index, index) {
+
+  // An assumed-size array (unknown trailing extent) passed without a
+  // descriptor, whose acc clause operand is not produced by an [hl]fir.declare
+  // (so no shape is recoverable). It must produce no bounds.
+  func.func @_QPassumed_size_no_descriptor(%arg0: !fir.ref<!fir.array<?x?xf32>> {fir.bindc_name = "a"}) {
+    %0 = fir.convert %arg0 : (!fir.ref<!fir.array<?x?xf32>>) -> !fir.ref<!fir.array<?x?xf32>>
+    %1 = acc.copyin varPtr(%0 : !fir.ref<!fir.array<?x?xf32>>) -> !fir.ref<!fir.array<?x?xf32>> {name = "a", structured = false}
+    acc.enter_data dataOperands(%1 : !fir.ref<!fir.array<?x?xf32>>)
+    return
+  }
+  // CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<?x?xf32>>) -> !fir.ref<!fir.array<?x?xf32>> {name = "a", structured = false}
+  // CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<?x?xf32>>
+  // CHECK: Type category: array
+  // CHECK: Has unknown dimensions: true
+  // CHECK-NOT: Bound[
 }



More information about the flang-commits mailing list