1! Test allocatable assignments 2! RUN: bbc -emit-fir %s -o - | FileCheck %s 3 4module alloc_assign 5contains 6 7! ----------------------------------------------------------------------------- 8! Test simple scalar RHS 9! ----------------------------------------------------------------------------- 10 11! CHECK-LABEL: func @_QMalloc_assignPtest_simple_scalar( 12! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<f32>>>{{.*}}) { 13subroutine test_simple_scalar(x) 14 real, allocatable :: x 15! CHECK: %[[VAL_1:.*]] = arith.constant 4.200000e+01 : f32 16! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<f32>>> 17! CHECK: %[[VAL_3:.*]] = fir.box_addr %[[VAL_2]] : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32> 18! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.heap<f32>) -> i64 19! CHECK: %[[VAL_5:.*]] = arith.constant 0 : i64 20! CHECK: %[[VAL_6:.*]] = arith.cmpi ne, %[[VAL_4]], %[[VAL_5]] : i64 21! CHECK: %[[VAL_7:.*]]:2 = fir.if %[[VAL_6]] -> (i1, !fir.heap<f32>) { 22! CHECK: %[[VAL_8:.*]] = arith.constant false 23! CHECK: %[[VAL_9:.*]] = fir.if %[[VAL_8]] -> (!fir.heap<f32>) { 24! CHECK: %[[VAL_10:.*]] = fir.allocmem f32 {uniq_name = ".auto.alloc"} 25! CHECK: fir.result %[[VAL_10]] : !fir.heap<f32> 26! CHECK: } else { 27! CHECK: fir.result %[[VAL_3]] : !fir.heap<f32> 28! CHECK: } 29! CHECK: fir.result %[[VAL_8]], %[[VAL_11:.*]] : i1, !fir.heap<f32> 30! CHECK: } else { 31! CHECK: %[[VAL_12:.*]] = arith.constant true 32! CHECK: %[[VAL_13:.*]] = fir.allocmem f32 {uniq_name = ".auto.alloc"} 33! CHECK: fir.result %[[VAL_12]], %[[VAL_13]] : i1, !fir.heap<f32> 34! CHECK: } 35! CHECK: fir.store %[[VAL_1]] to %[[VAL_14:.*]]#1 : !fir.heap<f32> 36! CHECK: fir.if %[[VAL_14]]#0 { 37! CHECK: fir.if %[[VAL_6]] { 38! CHECK: fir.freemem %[[VAL_3]] 39! CHECK: } 40! CHECK: %[[VAL_15:.*]] = fir.embox %[[VAL_14]]#1 : (!fir.heap<f32>) -> !fir.box<!fir.heap<f32>> 41! CHECK: fir.store %[[VAL_15]] to %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<f32>>> 42! CHECK: } 43 x = 42. 44end subroutine 45 46! CHECK-LABEL: func @_QMalloc_assignPtest_simple_local_scalar() { 47subroutine test_simple_local_scalar() 48 real, allocatable :: x 49! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.heap<f32> {uniq_name = "_QMalloc_assignFtest_simple_local_scalarEx.addr"} 50! CHECK: %[[VAL_2:.*]] = fir.zero_bits !fir.heap<f32> 51! CHECK: fir.store %[[VAL_2]] to %[[VAL_1]] : !fir.ref<!fir.heap<f32>> 52! CHECK: %[[VAL_3:.*]] = arith.constant 4.200000e+01 : f32 53! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.heap<f32>> 54! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (!fir.heap<f32>) -> i64 55! CHECK: %[[VAL_6:.*]] = arith.constant 0 : i64 56! CHECK: %[[VAL_7:.*]] = arith.cmpi ne, %[[VAL_5]], %[[VAL_6]] : i64 57! CHECK: %[[VAL_8:.*]]:2 = fir.if %[[VAL_7]] -> (i1, !fir.heap<f32>) { 58! CHECK: %[[VAL_9:.*]] = arith.constant false 59! CHECK: %[[VAL_10:.*]] = fir.if %[[VAL_9]] -> (!fir.heap<f32>) { 60! CHECK: %[[VAL_11:.*]] = fir.allocmem f32 {uniq_name = ".auto.alloc"} 61! CHECK: fir.result %[[VAL_11]] : !fir.heap<f32> 62! CHECK: } else { 63! CHECK: fir.result %[[VAL_4]] : !fir.heap<f32> 64! CHECK: } 65! CHECK: fir.result %[[VAL_9]], %[[VAL_12:.*]] : i1, !fir.heap<f32> 66! CHECK: } else { 67! CHECK: %[[VAL_13:.*]] = arith.constant true 68! CHECK: %[[VAL_14:.*]] = fir.allocmem f32 {uniq_name = ".auto.alloc"} 69! CHECK: fir.result %[[VAL_13]], %[[VAL_14]] : i1, !fir.heap<f32> 70! CHECK: } 71! CHECK: fir.store %[[VAL_3]] to %[[VAL_15:.*]]#1 : !fir.heap<f32> 72! CHECK: fir.if %[[VAL_15]]#0 { 73! CHECK: fir.if %[[VAL_7]] { 74! CHECK: fir.freemem %[[VAL_4]] 75! CHECK: } 76! CHECK: fir.store %[[VAL_15]]#1 to %[[VAL_1]] : !fir.ref<!fir.heap<f32>> 77! CHECK: } 78 x = 42. 79end subroutine 80 81end module 82