| 1 |
! RUN: bbc -emit-hlfir %s -o - | FileCheck %s |
| 2 |
! Test lowering of extension of SOURCE allocation (non deferred length |
| 3 |
! of character allocate-object need not to match the SOURCE length, truncation |
| 4 |
! and padding are performed instead as in assignments). |
| 5 |
|
| 6 |
subroutine test() |
| 7 |
! CHECK-LABEL: func.func @_QPtest() { |
| 8 |
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}} {{.*}}Ec_deferred |
| 9 |
! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %{{.*}} typeparams %[[VAL_6:.*]] {{.*}}Ec_longer |
| 10 |
! CHECK: %[[VAL_14:.*]]:2 = hlfir.declare %{{.*}} typeparams %[[VAL_11:.*]] {{.*}}Ec_shorter |
| 11 |
! CHECK: %[[VAL_17:.*]]:2 = hlfir.declare %{{.*}} typeparams %[[VAL_16:.*]] {{{.*}}Ec_source |
| 12 |
character(5) :: c_source = "hello" |
| 13 |
character(2), allocatable :: c_shorter |
| 14 |
character(:), allocatable :: c_deferred |
| 15 |
character(7), allocatable :: c_longer |
| 16 |
! CHECK: %[[VAL_18:.*]] = arith.constant false |
| 17 |
! CHECK: %[[VAL_22:.*]] = fir.embox %[[VAL_17]]#1 : (!fir.ref<!fir.char<1,5>>) -> !fir.box<!fir.char<1,5>> |
| 18 |
|
| 19 |
! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_14]]#1 : (!fir.ref<!fir.box<!fir.heap<!fir.char<1,2>>>>) -> !fir.ref<!fir.box<none>> |
| 20 |
! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_22]] : (!fir.box<!fir.char<1,5>>) -> !fir.box<none> |
| 21 |
! CHECK: %[[VAL_26:.*]] = fir.call @_FortranAAllocatableAllocateSource(%[[VAL_23]], %[[VAL_24]], %[[VAL_18]] |
| 22 |
|
| 23 |
! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_4]]#1 : (!fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>) -> !fir.ref<!fir.box<none>> |
| 24 |
! CHECK: %[[VAL_28:.*]] = fir.convert %[[VAL_16]] : (index) -> i64 |
| 25 |
! CHECK: %[[VAL_29:.*]] = arith.constant 1 : i32 |
| 26 |
! CHECK: %[[VAL_30:.*]] = arith.constant 0 : i32 |
| 27 |
! CHECK: %[[VAL_31:.*]] = arith.constant 0 : i32 |
| 28 |
! CHECK: %[[VAL_32:.*]] = fir.call @_FortranAAllocatableInitCharacterForAllocate(%[[VAL_27]], %[[VAL_28]], %[[VAL_29]], %[[VAL_30]], %[[VAL_31]] |
| 29 |
! CHECK: %[[VAL_33:.*]] = fir.convert %[[VAL_4]]#1 : (!fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>) -> !fir.ref<!fir.box<none>> |
| 30 |
! CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_22]] : (!fir.box<!fir.char<1,5>>) -> !fir.box<none> |
| 31 |
! CHECK: %[[VAL_36:.*]] = fir.call @_FortranAAllocatableAllocateSource(%[[VAL_33]], %[[VAL_34]], %[[VAL_18]], |
| 32 |
|
| 33 |
! CHECK-NOT: AllocatableInitCharacterForAllocate |
| 34 |
! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_9]]#1 : (!fir.ref<!fir.box<!fir.heap<!fir.char<1,7>>>>) -> !fir.ref<!fir.box<none>> |
| 35 |
! CHECK: %[[VAL_38:.*]] = fir.convert %[[VAL_22]] : (!fir.box<!fir.char<1,5>>) -> !fir.box<none> |
| 36 |
! CHECK: %[[VAL_40:.*]] = fir.call @_FortranAAllocatableAllocateSource(%[[VAL_37]], %[[VAL_38]], %[[VAL_18]], |
| 37 |
allocate(c_shorter, c_deferred, c_longer, source=c_source) |
| 38 |
|
| 39 |
! Expect at runtime: |
| 40 |
! ZZheZZ |
| 41 |
! ZZhelloZZ |
| 42 |
! ZZhello ZZ |
| 43 |
write(*,"('ZZ',A,'ZZ')") c_shorter |
| 44 |
write(*,"('ZZ',A,'ZZ')") c_deferred |
| 45 |
write(*,"('ZZ',A,'ZZ')") c_longer |
| 46 |
end subroutine |
| 47 |
|
| 48 |
call test() |
| 49 |
end |