1 ! This test checks lowering of OpenMP Threadprivate Directive.
2 ! Test for non-character non-SAVEd non-initialized scalars with or without
3 ! allocatable or pointer attribute in main program.
5 !RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
13 real, allocatable
:: b
15 !CHECK-DAG: %[[A:.*]] = fir.address_of(@_QFEa) : !fir.ref<!fir.box<!fir.ptr<i32>>>
16 !CHECK-DAG: %[[OMP_A:.*]] = omp.threadprivate %[[A]] : !fir.ref<!fir.box<!fir.ptr<i32>>> -> !fir.ref<!fir.box<!fir.ptr<i32>>>
17 !CHECK-DAG: %[[OMP_A_DECL:.*]]:2 = hlfir.declare %[[OMP_A]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFEa"} : (!fir.ref<!fir.box<!fir.ptr<i32>>>) -> (!fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.ref<!fir.box<!fir.ptr<i32>>>)
18 !CHECK-DAG: %[[B:.*]] = fir.address_of(@_QFEb) : !fir.ref<!fir.box<!fir.heap<f32>>>
19 !CHECK-DAG: %[[OMP_B:.*]] = omp.threadprivate %[[B]] : !fir.ref<!fir.box<!fir.heap<f32>>> -> !fir.ref<!fir.box<!fir.heap<f32>>>
20 !CHECK-DAG: %[[OMP_B_DECL:.*]]:2 = hlfir.declare %[[OMP_B]] {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFEb"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)
21 !CHECK-DAG: %[[W:.*]] = fir.address_of(@_QFEw) : !fir.ref<complex<f32>>
22 !CHECK-DAG: %[[OMP_W:.*]] = omp.threadprivate %[[W]] : !fir.ref<complex<f32>> -> !fir.ref<complex<f32>>
23 !CHECK-DAG: %[[OMP_W_DECL:.*]]:2 = hlfir.declare %[[OMP_W]] {uniq_name = "_QFEw"} : (!fir.ref<complex<f32>>) -> (!fir.ref<complex<f32>>, !fir.ref<complex<f32>>)
24 !CHECK-DAG: %[[X:.*]] = fir.address_of(@_QFEx) : !fir.ref<i32>
25 !CHECK-DAG: %[[OMP_X:.*]] = omp.threadprivate %[[X]] : !fir.ref<i32> -> !fir.ref<i32>
26 !CHECK-DAG: %[[OMP_X_DECL:.*]]:2 = hlfir.declare %[[OMP_X]] {uniq_name = "_QFEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
27 !CHECK-DAG: %[[Y:.*]] = fir.address_of(@_QFEy) : !fir.ref<f32>
28 !CHECK-DAG: %[[OMP_Y:.*]] = omp.threadprivate %[[Y]] : !fir.ref<f32> -> !fir.ref<f32>
29 !CHECK-DAG: %[[OMP_Y_DECL:.*]]:2 = hlfir.declare %[[OMP_Y]] {uniq_name = "_QFEy"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
30 !CHECK-DAG: %[[Z:.*]] = fir.address_of(@_QFEz) : !fir.ref<!fir.logical<4>>
31 !CHECK-DAG: %[[OMP_Z:.*]] = omp.threadprivate %[[Z]] : !fir.ref<!fir.logical<4>> -> !fir.ref<!fir.logical<4>>
32 !CHECK-DAG: %[[OMP_Z_DECL:.*]]:2 = hlfir.declare %[[OMP_Z]] {uniq_name = "_QFEz"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
33 !$omp threadprivate(x, y, z, w, a, b)
37 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_X_DECL]]#0 : !fir.ref<i32>
38 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_Y_DECL]]#0 : !fir.ref<f32>
39 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_Z_DECL]]#0 : !fir.ref<!fir.logical<4>>
40 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_W_DECL]]#0 : !fir.ref<complex<f32>>
41 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_A_DECL]]#0 : !fir.ref<!fir.box<!fir.ptr<i32>>>
42 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_B_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
43 print *, x
, y
, z
, w
, a
, b
46 !CHECK-DAG: %[[X_PVT:.*]] = omp.threadprivate %[[X]] : !fir.ref<i32> -> !fir.ref<i32>
47 !CHECK-DAG: %[[X_PVT_DECL:.*]]:2 = hlfir.declare %[[X_PVT]] {uniq_name = "_QFEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
48 !CHECK-DAG: %[[Y_PVT:.*]] = omp.threadprivate %[[Y]] : !fir.ref<f32> -> !fir.ref<f32>
49 !CHECK-DAG: %[[Y_PVT_DECL:.*]]:2 = hlfir.declare %[[Y_PVT]] {uniq_name = "_QFEy"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
50 !CHECK-DAG: %[[Z_PVT:.*]] = omp.threadprivate %[[Z]] : !fir.ref<!fir.logical<4>> -> !fir.ref<!fir.logical<4>>
51 !CHECK-DAG: %[[Z_PVT_DECL:.*]]:2 = hlfir.declare %[[Z_PVT]] {uniq_name = "_QFEz"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
52 !CHECK-DAG: %[[W_PVT:.*]] = omp.threadprivate %[[W]] : !fir.ref<complex<f32>> -> !fir.ref<complex<f32>>
53 !CHECK-DAG: %[[W_PVT_DECL:.*]]:2 = hlfir.declare %[[W_PVT]] {uniq_name = "_QFEw"} : (!fir.ref<complex<f32>>) -> (!fir.ref<complex<f32>>, !fir.ref<complex<f32>>)
54 !CHECK-DAG: %[[A_PVT:.*]] = omp.threadprivate %[[A]] : !fir.ref<!fir.box<!fir.ptr<i32>>> -> !fir.ref<!fir.box<!fir.ptr<i32>>>
55 !CHECK-DAG: %[[A_PVT_DECL:.*]]:2 = hlfir.declare %[[A_PVT]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFEa"} : (!fir.ref<!fir.box<!fir.ptr<i32>>>) -> (!fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.ref<!fir.box<!fir.ptr<i32>>>)
56 !CHECK-DAG: %[[B_PVT:.*]] = omp.threadprivate %[[B]] : !fir.ref<!fir.box<!fir.heap<f32>>> -> !fir.ref<!fir.box<!fir.heap<f32>>>
57 !CHECK-DAG: %[[B_PVT_DECL:.*]]:2 = hlfir.declare %[[B_PVT]] {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFEb"} : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>)
58 !CHECK-DAG: %{{.*}} = fir.load %[[X_PVT_DECL]]#0 : !fir.ref<i32>
59 !CHECK-DAG: %{{.*}} = fir.load %[[Y_PVT_DECL]]#0 : !fir.ref<f32>
60 !CHECK-DAG: %{{.*}} = fir.load %[[Z_PVT_DECL]]#0 : !fir.ref<!fir.logical<4>>
61 !CHECK-DAG: %{{.*}} = fir.load %[[W_PVT_DECL]]#0 : !fir.ref<complex<f32>>
62 !CHECK-DAG: %{{.*}} = fir.load %[[A_PVT_DECL]]#0 : !fir.ref<!fir.box<!fir.ptr<i32>>>
63 !CHECK-DAG: %{{.*}} = fir.load %[[B_PVT_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
64 print *, x
, y
, z
, w
, a
, b
67 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_X_DECL]]#0 : !fir.ref<i32>
68 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_Y_DECL]]#0 : !fir.ref<f32>
69 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_Z_DECL]]#0 : !fir.ref<!fir.logical<4>>
70 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_W_DECL]]#0 : !fir.ref<complex<f32>>
71 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_A_DECL]]#0 : !fir.ref<!fir.box<!fir.ptr<i32>>>
72 !CHECK-DAG: %{{.*}} = fir.load %[[OMP_B_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
73 print *, x
, y
, z
, w
, a
, b
77 !CHECK-DAG: fir.global internal @_QFEa : !fir.box<!fir.ptr<i32>> {
78 !CHECK-DAG: [[Z0:%.*]] = fir.zero_bits !fir.ptr<i32>
79 !CHECK-DAG: [[E0:%.*]] = fir.embox [[Z0]] : (!fir.ptr<i32>) -> !fir.box<!fir.ptr<i32>>
80 !CHECK-DAG: fir.has_value [[E0]] : !fir.box<!fir.ptr<i32>>
82 !CHECK-DAG: fir.global internal @_QFEb : !fir.box<!fir.heap<f32>> {
83 !CHECK-DAG: [[Z1:%.*]] = fir.zero_bits !fir.heap<f32>
84 !CHECK-DAG: [[E1:%.*]] = fir.embox [[Z1]] : (!fir.heap<f32>) -> !fir.box<!fir.heap<f32>>
85 !CHECK-DAG: fir.has_value [[E1]] : !fir.box<!fir.heap<f32>>
87 !CHECK-DAG: fir.global internal @_QFEw : complex<f32> {
88 !CHECK-DAG: [[Z2:%.*]] = fir.undefined complex<f32>
89 !CHECK-DAG: fir.has_value [[Z2]] : complex<f32>
91 !CHECK-DAG: fir.global internal @_QFEx : i32 {
92 !CHECK-DAG: [[Z3:%.*]] = fir.undefined i32
93 !CHECK-DAG: fir.has_value [[Z3]] : i32
95 !CHECK-DAG: fir.global internal @_QFEy : f32 {
96 !CHECK-DAG: [[Z4:%.*]] = fir.undefined f32
97 !CHECK-DAG: fir.has_value [[Z4]] : f32
99 !CHECK-DAG: fir.global internal @_QFEz : !fir.logical<4> {
100 !CHECK-DAG: [[Z5:%.*]] = fir.undefined !fir.logical<4>
101 !CHECK-DAG: fir.has_value [[Z5]] : !fir.logical<4>