[flang-commits] [flang] [flang] fix fir.ref<fir.box<..>> type conversion in FIRToMemRefTypeConverter (PR #204271)
via flang-commits
flang-commits at lists.llvm.org
Wed Jun 17 07:18:58 PDT 2026
================
@@ -66,3 +66,40 @@ func.func @test_fir_llvm_ptr_to_index() {
// CHECK: Generated: %{{.*}} = fir.convert %{{.*}} : (!fir.llvm_ptr<i8>) -> index
return
}
+
+// -----
+
+// !fir.alloca !fir.box<...> produces a !fir.ref<!fir.box<...>> — the
+// pointer-to-descriptor type used for assumed-shape dummy arguments and
+// allocatable reduction variables. getAsMemRefType must yield the same
+// strided memref as the box itself rather than asserting.
+func.func @test_fir_ref_box_array_to_strided_memref() {
+ %0 = fir.alloca !fir.box<!fir.array<?xi32>> {test.cast, cast_dest = memref<?xi32, strided<[?], offset: ?>>}
+ // CHECK: Successfully generated cast for operation: %{{.*}} = fir.alloca !fir.box<!fir.array<?xi32>>{{.*}}
+ // CHECK: Cast result type: memref<?xi32, strided<[?], offset: ?>>
+ // CHECK: Generated: %{{.*}} = fir.convert %{{.*}} : (!fir.ref<!fir.box<!fir.array<?xi32>>>) -> memref<?xi32, strided<[?], offset: ?>>
+ return
+}
+
+// -----
+
+// Same as above for a 2-D assumed-shape array.
+func.func @test_fir_ref_box_2d_array_to_strided_memref() {
+ %0 = fir.alloca !fir.box<!fir.array<?x?xf64>> {test.cast, cast_dest = memref<?x?xf64, strided<[?, ?], offset: ?>>}
+ // CHECK: Successfully generated cast for operation: %{{.*}} = fir.alloca !fir.box<!fir.array<?x?xf64>>{{.*}}
+ // CHECK: Cast result type: memref<?x?xf64, strided<[?, ?], offset: ?>>
+ // CHECK: Generated: %{{.*}} = fir.convert %{{.*}} : (!fir.ref<!fir.box<!fir.array<?x?xf64>>>) -> memref<?x?xf64, strided<[?, ?], offset: ?>>
----------------
jeanPerier wrote:
Do you want to get hold of a `memref` for the data or the descriptor in the end?
Looking at the IR, it looks like the convert result is a memref for the data, which I think is too much action for a fir.convert if you are strating from a descriptor address. I think you need to insert a fir.load somewhere and convert that into the memref, otherwise the fir.convert is now doing a read of the descriptor and I think that is not in line with its `NoMemoryEffect` interface.
https://github.com/llvm/llvm-project/pull/204271
More information about the flang-commits
mailing list