brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.5 KiB · 60b7de3 Raw
197 lines · plain
1! RUN: bbc --use-desc-for-alloc=false -emit-fir -hlfir=false %s -o - | FileCheck %s2 3! Test lowering of allocatables using runtime for allocate/deallcoate statements.4! CHECK-LABEL: _QPfooscalar5subroutine fooscalar()6  ! Test lowering of local allocatable specification7  real, allocatable :: x8  ! CHECK: %[[xAddrVar:.*]] = fir.alloca !fir.heap<f32> {{{.*}}uniq_name = "_QFfooscalarEx.addr"}9  ! CHECK: %[[nullAddr:.*]] = fir.zero_bits !fir.heap<f32>10  ! CHECK: fir.store %[[nullAddr]] to %[[xAddrVar]] : !fir.ref<!fir.heap<f32>>11 12  ! Test allocation of local allocatables13  allocate(x)14  ! CHECK: %[[alloc:.*]] = fir.allocmem f32 {{{.*}}uniq_name = "_QFfooscalarEx.alloc"}15  ! CHECK: fir.store %[[alloc]] to %[[xAddrVar]] : !fir.ref<!fir.heap<f32>>16 17  ! Test reading allocatable bounds and extents18  print *, x19  ! CHECK: %[[xAddr1:.*]] = fir.load %[[xAddrVar]] : !fir.ref<!fir.heap<f32>>20  ! CHECK: = fir.load %[[xAddr1]] : !fir.heap<f32>21 22  ! Test deallocation23  deallocate(x)24  ! CHECK: %[[xAddr2:.*]] = fir.load %[[xAddrVar]] : !fir.ref<!fir.heap<f32>>25  ! CHECK: fir.freemem %[[xAddr2]]26  ! CHECK: %[[nullAddr1:.*]] = fir.zero_bits !fir.heap<f32>27  ! fir.store %[[nullAddr1]] to %[[xAddrVar]] : !fir.ref<!fir.heap<f32>>28end subroutine29 30! CHECK-LABEL: _QPfoodim131subroutine foodim1()32  ! Test lowering of local allocatable specification33  real, allocatable :: x(:)34  ! CHECK-DAG: %[[xAddrVar:.*]] = fir.alloca !fir.heap<!fir.array<?xf32>> {{{.*}}uniq_name = "_QFfoodim1Ex.addr"}35  ! CHECK-DAG: %[[xLbVar:.*]] = fir.alloca index {{{.*}}uniq_name = "_QFfoodim1Ex.lb0"}36  ! CHECK-DAG: %[[xExtVar:.*]] = fir.alloca index {{{.*}}uniq_name = "_QFfoodim1Ex.ext0"}37  ! CHECK: %[[nullAddr:.*]] = fir.zero_bits !fir.heap<!fir.array<?xf32>>38  ! CHECK: fir.store %[[nullAddr]] to %[[xAddrVar]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>39 40  ! Test allocation of local allocatables41  allocate(x(42:100))42  ! CHECK-DAG: %[[c42:.*]] = fir.convert %c42{{.*}} : (i32) -> index43  ! CHECK-DAG: %[[c100:.*]] = fir.convert %c100_i32 : (i32) -> index44  ! CHECK-DAG: %[[diff:.*]] = arith.subi %[[c100]], %[[c42]] : index45  ! CHECK: %[[rawExtent:.*]] = arith.addi %[[diff]], %c1{{.*}} : index46  ! CHECK: %[[extentPositive:.*]] = arith.cmpi sgt, %[[rawExtent]], %c0{{.*}} : index47  ! CHECK: %[[extent:.*]] = arith.select %[[extentPositive]], %[[rawExtent]], %c0{{.*}} : index48  ! CHECK: %[[alloc:.*]] = fir.allocmem !fir.array<?xf32>, %[[extent]] {{{.*}}uniq_name = "_QFfoodim1Ex.alloc"}49  ! CHECK-DAG: fir.store %[[alloc]] to %[[xAddrVar]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>50  ! CHECK-DAG: fir.store %[[extent]] to %[[xExtVar]] : !fir.ref<index>51  ! CHECK-DAG: fir.store %[[c42]] to %[[xLbVar]] : !fir.ref<index>52 53  ! Test reading allocatable bounds and extents54  print *, x(42)55  ! CHECK-DAG: fir.load %[[xLbVar]] : !fir.ref<index>56  ! CHECK-DAG: fir.load %[[xAddrVar]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>57 58  deallocate(x)59  ! CHECK: %[[xAddr1:.*]] = fir.load %{{.*}} : !fir.ref<!fir.heap<!fir.array<?xf32>>>60  ! CHECK: fir.freemem %[[xAddr1]]61  ! CHECK: %[[nullAddr1:.*]] = fir.zero_bits !fir.heap<!fir.array<?xf32>>62  ! CHECK: fir.store %[[nullAddr1]] to %[[xAddrVar]] : !fir.ref<!fir.heap<!fir.array<?xf32>>>63end subroutine64 65! CHECK-LABEL: _QPfoodim266subroutine foodim2()67  ! Test lowering of local allocatable specification68  real, allocatable :: x(:, :)69  ! CHECK-DAG: fir.alloca !fir.heap<!fir.array<?x?xf32>> {{{.*}}uniq_name = "_QFfoodim2Ex.addr"}70end subroutine71 72! test lowering of character allocatables. Focus is placed on the length handling73! CHECK-LABEL: _QPchar_deferred(74subroutine char_deferred(n)75  integer :: n76  character(:), allocatable :: c77  ! CHECK-DAG: %[[cAddrVar:.*]] = fir.alloca !fir.heap<!fir.char<1,?>> {{{.*}}uniq_name = "_QFchar_deferredEc.addr"}78  ! CHECK-DAG: %[[cLenVar:.*]] = fir.alloca index {{{.*}}uniq_name = "_QFchar_deferredEc.len"}79  allocate(character(10):: c)80  ! CHECK: %[[c10:.]] = fir.convert %c10_i32 : (i32) -> index81  ! CHECK: fir.allocmem !fir.char<1,?>(%[[c10]] : index) {{{.*}}uniq_name = "_QFchar_deferredEc.alloc"}82  ! CHECK: fir.store %[[c10]] to %[[cLenVar]] : !fir.ref<index>83  deallocate(c)84  ! CHECK: fir.freemem %{{.*}}85  allocate(character(n):: c)86  ! CHECK: %[[n:.*]] = fir.load %arg0 : !fir.ref<i32>87  ! CHECK: %[[nPositive:.*]] = arith.cmpi sgt, %[[n]], %c0{{.*}} : i3288  ! CHECK: %[[ns:.*]] = arith.select %[[nPositive]], %[[n]], %c0{{.*}} : i3289  ! CHECK: %[[ni:.*]] = fir.convert %[[ns]] : (i32) -> index90  ! CHECK: fir.allocmem !fir.char<1,?>(%[[ni]] : index) {{{.*}}uniq_name = "_QFchar_deferredEc.alloc"}91  ! CHECK: fir.store %[[ni]] to %[[cLenVar]] : !fir.ref<index>92 93  call bar(c)94  ! CHECK-DAG: %[[cLen:.*]] = fir.load %[[cLenVar]] : !fir.ref<index>95  ! CHECK-DAG: %[[cAddr:.*]] = fir.load %[[cAddrVar]] : !fir.ref<!fir.heap<!fir.char<1,?>>>96  ! CHECK: fir.emboxchar %[[cAddr]], %[[cLen]] : (!fir.heap<!fir.char<1,?>>, index) -> !fir.boxchar<1>97end subroutine98 99! CHECK-LABEL: _QPchar_explicit_cst(100subroutine char_explicit_cst(n)101  integer :: n102  character(10), allocatable :: c103  ! CHECK-DAG: %[[cLen:.*]] = arith.constant 10 : index104  ! CHECK-DAG: %[[cAddrVar:.*]] = fir.alloca !fir.heap<!fir.char<1,10>> {{{.*}}uniq_name = "_QFchar_explicit_cstEc.addr"}105  ! CHECK-NOT: "_QFchar_explicit_cstEc.len"106  allocate(c)107  ! CHECK: fir.allocmem !fir.char<1,10> {{{.*}}uniq_name = "_QFchar_explicit_cstEc.alloc"}108  deallocate(c)109  ! CHECK: fir.freemem %{{.*}}110  allocate(character(n):: c)111  ! CHECK: fir.allocmem !fir.char<1,10> {{{.*}}uniq_name = "_QFchar_explicit_cstEc.alloc"}112  deallocate(c)113  ! CHECK: fir.freemem %{{.*}}114  allocate(character(10):: c)115  ! CHECK: fir.allocmem !fir.char<1,10> {{{.*}}uniq_name = "_QFchar_explicit_cstEc.alloc"}116  call bar(c)117  ! CHECK: %[[cAddr:.*]] = fir.load %[[cAddrVar]] : !fir.ref<!fir.heap<!fir.char<1,10>>>118  ! CHECK: fir.emboxchar %[[cAddr]], %[[cLen]] : (!fir.heap<!fir.char<1,10>>, index) -> !fir.boxchar<1>119end subroutine120 121! CHECK-LABEL: _QPchar_explicit_dyn(122subroutine char_explicit_dyn(l1, l2)123  integer :: l1, l2124  character(l1), allocatable :: c125  ! CHECK: %[[l1:.*]] = fir.load %arg0 : !fir.ref<i32>126  ! CHECK: %[[c0_i32:.*]] = arith.constant 0 : i32127  ! CHECK: %[[cmp:.*]] = arith.cmpi sgt, %[[l1]], %[[c0_i32]] : i32128  ! CHECK: %[[cLen:.*]] = arith.select %[[cmp]], %[[l1]], %[[c0_i32]] : i32129  ! CHECK: %[[cAddrVar:.*]] = fir.alloca !fir.heap<!fir.char<1,?>> {{{.*}}uniq_name = "_QFchar_explicit_dynEc.addr"}130  ! CHECK-NOT: "_QFchar_explicit_dynEc.len"131  allocate(c)132  ! CHECK: %[[cLenCast1:.*]] = fir.convert %[[cLen]] : (i32) -> index133  ! CHECK: fir.allocmem !fir.char<1,?>(%[[cLenCast1]] : index) {{{.*}}uniq_name = "_QFchar_explicit_dynEc.alloc"}134  deallocate(c)135  ! CHECK: fir.freemem %{{.*}}136  allocate(character(l2):: c)137  ! CHECK: %[[cLenCast2:.*]] = fir.convert %[[cLen]] : (i32) -> index138  ! CHECK: fir.allocmem !fir.char<1,?>(%[[cLenCast2]] : index) {{{.*}}uniq_name = "_QFchar_explicit_dynEc.alloc"}139  deallocate(c)140  ! CHECK: fir.freemem %{{.*}}141  allocate(character(10):: c)142  ! CHECK: %[[cLenCast3:.*]] = fir.convert %[[cLen]] : (i32) -> index143  ! CHECK: fir.allocmem !fir.char<1,?>(%[[cLenCast3]] : index) {{{.*}}uniq_name = "_QFchar_explicit_dynEc.alloc"}144  call bar(c)145  ! CHECK-DAG: %[[cLenCast4:.*]] = fir.convert %[[cLen]] : (i32) -> index146  ! CHECK-DAG: %[[cAddr:.*]] = fir.load %[[cAddrVar]] : !fir.ref<!fir.heap<!fir.char<1,?>>>147  ! CHECK: fir.emboxchar %[[cAddr]], %[[cLenCast4]] : (!fir.heap<!fir.char<1,?>>, index) -> !fir.boxchar<1>148end subroutine149 150! CHECK-LABEL: _QPspecifiers(151subroutine specifiers152  allocatable jj1(:), jj2(:,:), jj3(:)153  ! CHECK: [[STAT:%[0-9]+]] = fir.alloca i32 {{{.*}}uniq_name = "_QFspecifiersEsss"}154  integer sss155  character*30 :: mmm = "None"156  ! CHECK: fir.call @_FortranAAllocatableSetBounds157  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableAllocate158  ! CHECK: fir.store [[RESULT]] to [[STAT]]159  ! CHECK: fir.if %{{[0-9]+}} {160  ! CHECK: fir.call @_FortranAAllocatableSetBounds161  ! CHECK: fir.call @_FortranAAllocatableSetBounds162  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableAllocate163  ! CHECK: fir.store [[RESULT]] to [[STAT]]164  ! CHECK: fir.if %{{[0-9]+}} {165  ! CHECK: fir.call @_FortranAAllocatableSetBounds166  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableAllocate167  ! CHECK: fir.store [[RESULT]] to [[STAT]]168  ! CHECK-NOT: fir.if %{{[0-9]+}} {169  ! CHECK-COUNT-2: }170  ! CHECK-NOT: }171  allocate(jj1(3), jj2(3,3), jj3(3), stat=sss, errmsg=mmm)172  ! CHECK: fir.call @_FortranAAllocatableSetBounds173  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableAllocate174  ! CHECK: fir.call @_FortranAAllocatableSetBounds175  ! CHECK: fir.call @_FortranAAllocatableSetBounds176  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableAllocate177  ! CHECK: fir.call @_FortranAAllocatableSetBounds178  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableAllocate179  allocate(jj1(3), jj2(3,3), jj3(3), stat=sss, errmsg=mmm)180  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableDeallocate181  ! CHECK: fir.store [[RESULT]] to [[STAT]]182  ! CHECK: fir.if %{{[0-9]+}} {183  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableDeallocate184  ! CHECK: fir.store [[RESULT]] to [[STAT]]185  ! CHECK: fir.if %{{[0-9]+}} {186  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableDeallocate187  ! CHECK: fir.store [[RESULT]] to [[STAT]]188  ! CHECK-NOT: fir.if %{{[0-9]+}} {189  ! CHECK-COUNT-2: }190  ! CHECK-NOT: }191  deallocate(jj1, jj2, jj3, stat=sss, errmsg=mmm)192  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableDeallocate193  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableDeallocate194  ! CHECK: [[RESULT:%[0-9]+]] = fir.call @_FortranAAllocatableDeallocate195  deallocate(jj1, jj2, jj3, stat=sss, errmsg=mmm)196end subroutine specifiers197