Skip to content

Commit b78e24e

Browse files
jeanPerierAlexisPerry
authored andcommitted
[flang] implement assumed-rank in ENTRY (llvm#96111)
With `createUnallocatedBox` utility change from llvm#96106 , the TODO for assumed-rank in entry can simply be lifted and test is added. The key is that a unallocated assumed-rank descriptor is created with rank zero in the entry where an assumed-rank dummy from some other entry do not appear as a dummy (the symbol must still be mapped to some valid value because the symbol could be used in code that would be unreachable at runtime, but that the compiler must still generate).
1 parent bb6b206 commit b78e24e

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

flang/lib/Lower/ConvertVariable.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,11 +2036,6 @@ void Fortran::lower::mapSymbolAttributes(
20362036
if (isUnusedEntryDummy) {
20372037
assert(!Fortran::semantics::IsAllocatableOrPointer(sym) &&
20382038
"handled above");
2039-
// Need to add support for allocatable assumed-rank to use
2040-
// logic below, or to simplify it and add codegen for fir.zero
2041-
// !fir.box<> instead.
2042-
if (isAssumedRank)
2043-
TODO(loc, "assumed rank in ENTRY");
20442039
// The box is read right away because lowering code does not expect
20452040
// a non pointer/allocatable symbol to be mapped to a MutableBox.
20462041
mlir::Type ty = converter.genType(var);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
! Test assumed-rank dummy argument that is not present in
2+
! all ENTRY statements.
3+
! RUN: bbc -emit-hlfir -allow-assumed-rank -o - %s | FileCheck %s
4+
5+
subroutine test_main_entry(x)
6+
real :: x(..)
7+
interface
8+
subroutine some_proc(x)
9+
real :: x(..)
10+
end subroutine
11+
end interface
12+
call some_proc(x)
13+
entry test_alternate_entry()
14+
call the_end()
15+
end subroutine
16+
! CHECK-LABEL: func.func @_QPtest_main_entry(
17+
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.bindc_name = "x"}) {
18+
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope
19+
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {uniq_name = "_QFtest_main_entryEx"} : (!fir.box<!fir.array<*:f32>>, !fir.dscope) -> (!fir.box<!fir.array<*:f32>>, !fir.box<!fir.array<*:f32>>)
20+
21+
! CHECK-LABEL: func.func @_QPtest_alternate_entry() {
22+
! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<*:f32>>>
23+
! CHECK: %[[VAL_1:.*]] = fir.zero_bits !fir.heap<f32>
24+
! CHECK: %[[VAL_2:.*]] = fir.embox %[[VAL_1]] : (!fir.heap<f32>) -> !fir.box<!fir.heap<f32>>
25+
! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.box<!fir.heap<f32>>) -> !fir.box<!fir.heap<!fir.array<*:f32>>>
26+
! CHECK: fir.store %[[VAL_3]] to %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>
27+
! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>
28+
! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_4]] {uniq_name = "_QFtest_main_entryEx"} : (!fir.box<!fir.heap<!fir.array<*:f32>>>) -> (!fir.box<!fir.heap<!fir.array<*:f32>>>, !fir.box<!fir.heap<!fir.array<*:f32>>>)

0 commit comments

Comments
 (0)