Skip to content

Commit e0bcf3a

Browse files
authored
[flang] Allow no type parameters for fir.pack_array. (#131662)
Arrays with assumed-length types are represented with a box without explicit length parameters. This patch fixes the verification to allow it for `fir.pack_array`.
1 parent 02b4522 commit e0bcf3a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,12 @@ static bool validTypeParams(mlir::Type dynTy, mlir::ValueRange typeParams,
388388
if (!allowParamsForBox)
389389
return typeParams.size() == 0;
390390

391+
// A boxed value may have no length parameters, when the lengths
392+
// are assumed. If dynamic lengths are used, then proceed
393+
// to the verification below.
394+
if (typeParams.size() == 0)
395+
return true;
396+
391397
dynTy = fir::getFortranElementType(dynTy);
392398
}
393399
// Derived type must have all type parameters satisfied.

flang/test/Fir/fir-ops.fir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,17 @@ func.func @test_pack_unpack_array(%arg0: !fir.ref<!fir.box<none>>, %arg1: !fir.b
968968
return
969969
}
970970

971+
// Test assumed-length character array packing.
972+
// CHECK-LABEL: func.func @test_pack_array_character(
973+
// CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?x!fir.char<1,?>>>) {
974+
func.func @test_pack_array_character(%arg0: !fir.box<!fir.array<?x!fir.char<1,?>>>) {
975+
// CHECK: %[[VAL_1:.*]] = fir.pack_array %[[VAL_0]] heap whole : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>
976+
%0 = fir.pack_array %arg0 heap whole : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>
977+
// CHECK: fir.unpack_array %[[VAL_1]] to %[[VAL_0]] heap no_copy : !fir.box<!fir.array<?x!fir.char<1,?>>>
978+
fir.unpack_array %0 to %arg0 heap no_copy : !fir.box<!fir.array<?x!fir.char<1,?>>>
979+
return
980+
}
981+
971982
// CHECK-LABEL: func.func @test_is_contiguous_box(
972983
func.func @test_is_contiguous_box(%arg0: !fir.class<!fir.type<sometype{i:i32}>>, %arg1: !fir.box<!fir.array<?x?xf32>>, %arg2: !fir.box<i32>) -> i1 {
973984
// CHECK: fir.is_contiguous_box %{{.*}} innermost : (!fir.class<!fir.type<sometype{i:i32}>>) -> i1

0 commit comments

Comments
 (0)