diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -1633,7 +1633,7 @@ Compute the internal coordinate address starting from a boxed value or unboxed memory reference. Returns a memory reference. When computing the coordinate of an array element, the rank of the array must be known and - the number of indexing expressions must equal the rank of the array. + the number of indexing expressions must not exceed the rank of the array. This operation will apply the access map from a boxed value implicitly. diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir --- a/flang/test/Fir/convert-to-llvm.fir +++ b/flang/test/Fir/convert-to-llvm.fir @@ -2471,11 +2471,11 @@ // ----- -func @coordinate_array_known_size_2d(%arg0: !fir.ref>, %arg1 : index, %arg2 : index) { +func @coordinate_array_known_size_2d_get_i32(%arg0: !fir.ref>, %arg1 : index, %arg2 : index) { %q = fir.coordinate_of %arg0, %arg1, %arg2 : (!fir.ref>, index, index) -> !fir.ref return } -// CHECK-LABEL: llvm.func @coordinate_array_known_size_2d( +// CHECK-LABEL: llvm.func @coordinate_array_known_size_2d_get_i32( // CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr>>, // CHECK-SAME: %[[VAL_1:.*]]: i64, // CHECK-SAME: %[[VAL_2:.*]]: i64) { @@ -2486,6 +2486,20 @@ // ----- +func @coordinate_array_known_size_2d_get_array(%arg0: !fir.ref>, %arg1 : index) { + %q = fir.coordinate_of %arg0, %arg1 : (!fir.ref>, index) -> !fir.ref> + return +} +// CHECK-LABEL: llvm.func @coordinate_array_known_size_2d_get_array( +// CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr>>, +// CHECK-SAME: %[[VAL_1:.*]]: i64) { +// CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(0 : i64) : i64 +// CHECK: %[[VAL_3:.*]] = llvm.getelementptr %[[VAL_0]][%[[VAL_2]], %[[VAL_1]]] : (!llvm.ptr>>, i64, i64) -> !llvm.ptr> +// CHECK: llvm.return +// CHECK: } + +// ----- + // 5.2. `fir.derived` func @coordinate_ref_derived(%arg0: !fir.ref>) { %idx = fir.field_index field_2, !fir.type