Skip to content

Commit

Permalink
[flang] implement passing assumed-size array to assumed-rank arguments (
Browse files Browse the repository at this point in the history
#87511)

Remove the TODO, the patch that ensured that the descriptor upper bound
is set to -1 was #79156.
  • Loading branch information
jeanPerier committed Apr 4, 2024
1 parent a9d963f commit d799be8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
9 changes: 0 additions & 9 deletions flang/lib/Lower/ConvertCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,15 +1340,6 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
} else {
addr = hlfir::genVariableRawAddress(loc, builder, entity);
}
// The last extent created for assumed-rank descriptors must be -1 (18.5.3
// point 5.). This should be done when creating the assumed-size shape for
// consistency.
if (auto baseBoxDummy = mlir::dyn_cast<fir::BaseBoxType>(dummyType))
if (baseBoxDummy.isAssumedRank())
if (const Fortran::semantics::Symbol *sym =
Fortran::evaluate::UnwrapWholeSymbolDataRef(*arg.entity))
if (Fortran::semantics::IsAssumedSizeArray(sym->GetUltimate()))
TODO(loc, "passing assumed-size to assumed-rank array");

// For ranked actual passed to assumed-rank dummy, the cast to assumed-rank
// box is inserted when building the fir.call op. Inserting it here would
Expand Down
23 changes: 17 additions & 6 deletions flang/test/Lower/HLFIR/assumed-rank-iface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,20 @@ subroutine int_allocatable_to_assumed_rank_opt(x)
! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_7]] : (!fir.box<!fir.array<?x?xi32>>) -> !fir.box<!fir.array<*:i32>>
! CHECK: fir.call @_QPint_opt_assumed_rank(%[[VAL_11]]) fastmath<contract> : (!fir.box<!fir.array<*:i32>>) -> ()

! TODO: set assumed size last extent to -1.
!subroutine int_r2_assumed_size_to_assumed_rank(x)
! use ifaces, only : int_assumed_rank
! integer :: x(10, *)
! call int_assumed_rank(x)
!end subroutine
subroutine int_r2_assumed_size_to_assumed_rank(x)
use ifaces, only : int_assumed_rank
integer :: x(10, *)
call int_assumed_rank(x)
end subroutine
! CHECK-LABEL: func.func @_QPint_r2_assumed_size_to_assumed_rank(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10x?xi32>> {fir.bindc_name = "x"}) {
! CHECK: %[[VAL_1:.*]] = arith.constant 10 : i64
! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]] : (i64) -> index
! CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
! CHECK: %[[VAL_4:.*]] = arith.cmpi sgt, %[[VAL_2]], %[[VAL_3]] : index
! CHECK: %[[VAL_5:.*]] = arith.select %[[VAL_4]], %[[VAL_2]], %[[VAL_3]] : index
! CHECK: %[[VAL_6:.*]] = arith.constant -1 : index
! CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_5]], %[[VAL_6]] : (index, index) -> !fir.shape<2>
! CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_7]]) {uniq_name = "_QFint_r2_assumed_size_to_assumed_rankEx"} : (!fir.ref<!fir.array<10x?xi32>>, !fir.shape<2>) -> (!fir.box<!fir.array<10x?xi32>>, !fir.ref<!fir.array<10x?xi32>>)
! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]]#0 : (!fir.box<!fir.array<10x?xi32>>) -> !fir.box<!fir.array<*:i32>>
! CHECK: fir.call @_QPint_assumed_rank(%[[VAL_9]]) fastmath<contract> : (!fir.box<!fir.array<*:i32>>) -> ()

0 comments on commit d799be8

Please sign in to comment.