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