1 ! Test lowering of internal procedure host association for global variables
2 ! A tuple function argument should not be created for associated globals, and
3 ! instead globals should be instantiated with a fir.address_of inside the
4 ! contained procedures.
5 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
7 module test_mod_used_in_host
8 integer :: i
, j_in_equiv
9 integer :: not_in_equiv
10 equivalence (i
,j_in_equiv
)
13 subroutine module_var()
14 use test_mod_used_in_host
18 print *, j_in_equiv
, not_in_equiv
21 ! CHECK-LABEL: func.func @_QFmodule_varPbar()
22 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QMtest_mod_used_in_hostEi) : !fir.ref<!fir.array<4xi8>>
23 ! CHECK: %[[VAL_1:.*]] = arith.constant 0 : index
24 ! CHECK: %[[VAL_2:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_1]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
25 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<i8>) -> !fir.ptr<i32>
26 ! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QMtest_mod_used_in_hostEnot_in_equiv) : !fir.ref<i32>
28 subroutine test_common()
30 integer, save :: j_in_equiv
31 integer, save :: not_in_equiv
32 equivalence (i(2),j_in_equiv
)
33 common /x
/ i
, not_in_equiv
37 print *, j_in_equiv
, not_in_equiv
40 ! CHECK-LABEL: func.func @_QFtest_commonPbar() attributes {fir.internal_proc} {
41 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QBx) : !fir.ref<!fir.array<12xi8>>
42 ! CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<12xi8>>) -> !fir.ref<!fir.array<?xi8>>
43 ! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index
44 ! CHECK: %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_2]] : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
45 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i8>) -> !fir.ptr<i32>
46 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<12xi8>>) -> !fir.ref<!fir.array<?xi8>>
47 ! CHECK: %[[VAL_6:.*]] = arith.constant 8 : index
48 ! CHECK: %[[VAL_7:.*]] = fir.coordinate_of %[[VAL_5]], %[[VAL_6]] : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
49 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (!fir.ref<i8>) -> !fir.ref<i32>
51 subroutine saved_equiv()
53 integer, save :: j_in_equiv
54 integer, save :: not_in_equiv
55 equivalence (i(2),j_in_equiv
)
59 print *, j_in_equiv
, not_in_equiv
62 ! CHECK-LABEL: func.func @_QFsaved_equivPbar() attributes {fir.internal_proc} {
63 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QFsaved_equivEi) : !fir.ref<!fir.array<8xi8>>
64 ! CHECK: %[[VAL_1:.*]] = arith.constant 4 : index
65 ! CHECK: %[[VAL_2:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_1]] : (!fir.ref<!fir.array<8xi8>>, index) -> !fir.ref<i8>
66 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<i8>) -> !fir.ptr<i32>
67 ! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QFsaved_equivEnot_in_equiv) : !fir.ref<i32>
69 subroutine mixed_capture()
70 integer, save :: saved_i
71 integer, save :: saved_j
72 equivalence (saved_i
, saved_j
)
82 ! CHECK-LABEL: func.func @_QFmixed_capturePbar(
83 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<tuple<!fir.ref<i32>>> {fir.host_assoc}) attributes {fir.internal_proc} {
84 ! CHECK: %[[VAL_1:.*]] = fir.address_of(@_QFmixed_captureEsaved_i) : !fir.ref<!fir.array<4xi8>>
85 ! CHECK: %[[VAL_2:.*]] = arith.constant 0 : index
86 ! CHECK: %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_1]], %[[VAL_2]] : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
87 ! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i8>) -> !fir.ptr<i32>
88 ! CHECK: %[[VAL_5:.*]] = arith.constant 0 : i32
89 ! CHECK: %[[VAL_6:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_5]] : (!fir.ref<tuple<!fir.ref<i32>>>, i32) -> !fir.llvm_ptr<!fir.ref<i32>>
90 ! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_6]] : !fir.llvm_ptr<!fir.ref<i32>>
91 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_4]] : (!fir.ptr<i32>) -> !fir.ref<i32>
92 ! CHECK: fir.call @_QPtest(%[[VAL_9]], %[[VAL_7]]) {{.*}} : (!fir.ref<i32>, !fir.ref<i32>) -> ()