| 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 -hlfir=false %s -o - | FileCheck %s |
| 6 |
|
| 7 |
module test_mod_used_in_host |
| 8 |
integer :: i, j_in_equiv |
| 9 |
integer :: not_in_equiv |
| 10 |
equivalence (i,j_in_equiv) |
| 11 |
end module |
| 12 |
|
| 13 |
subroutine module_var() |
| 14 |
use test_mod_used_in_host |
| 15 |
call bar() |
| 16 |
contains |
| 17 |
subroutine bar() |
| 18 |
print *, j_in_equiv, not_in_equiv |
| 19 |
end subroutine |
| 20 |
end subroutine |
| 21 |
! CHECK-LABEL: func.func private @_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> |
| 27 |
|
| 28 |
subroutine test_common() |
| 29 |
integer :: i(2) |
| 30 |
integer :: j_in_equiv |
| 31 |
integer :: not_in_equiv |
| 32 |
equivalence (i(2),j_in_equiv) |
| 33 |
common /x/ i, not_in_equiv |
| 34 |
call bar() |
| 35 |
contains |
| 36 |
subroutine bar() |
| 37 |
print *, j_in_equiv, not_in_equiv |
| 38 |
end subroutine |
| 39 |
end subroutine |
| 40 |
! CHECK-LABEL: func.func private @_QFtest_commonPbar() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} { |
| 41 |
! CHECK: %[[VAL_0:.*]] = fir.address_of(@x_) : !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> |
| 50 |
|
| 51 |
subroutine saved_equiv() |
| 52 |
integer, save :: i(2) |
| 53 |
integer, save :: j_in_equiv |
| 54 |
integer, save :: not_in_equiv |
| 55 |
equivalence (i(2),j_in_equiv) |
| 56 |
call bar() |
| 57 |
contains |
| 58 |
subroutine bar() |
| 59 |
print *, j_in_equiv, not_in_equiv |
| 60 |
end subroutine |
| 61 |
end subroutine |
| 62 |
! CHECK-LABEL: func.func private @_QFsaved_equivPbar() attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} { |
| 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> |
| 68 |
|
| 69 |
subroutine mixed_capture() |
| 70 |
integer, save :: saved_i |
| 71 |
integer, save :: saved_j |
| 72 |
equivalence (saved_i, saved_j) |
| 73 |
integer :: i |
| 74 |
integer :: j |
| 75 |
equivalence (i,j) |
| 76 |
call bar() |
| 77 |
contains |
| 78 |
subroutine bar() |
| 79 |
call test(saved_j, j) |
| 80 |
end subroutine |
| 81 |
end subroutine |
| 82 |
! CHECK-LABEL: func.func private @_QFmixed_capturePbar( |
| 83 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<tuple<!fir.ref<i32>>> {fir.host_assoc}) attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} { |
| 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>) -> () |