| 1 |
! RUN: bbc -emit-fir %s -o - | FileCheck %s |
| 2 |
|
| 3 |
! Test use of module data that is defined in this file. |
| 4 |
! TODO: similar tests for the functions that are using the modules, but without the |
| 5 |
! module being defined in this file. This require a front-end fix to be pushed first |
| 6 |
! so |
| 7 |
|
| 8 |
! Module m2 defines simple data |
| 9 |
module m2 |
| 10 |
real :: x |
| 11 |
integer :: y(100) |
| 12 |
contains |
| 13 |
! CHECK-LABEL: func @_QMm2Pfoo() |
| 14 |
real function foo() |
| 15 |
! CHECK-DAG: fir.address_of(@_QMm2Ex) : !fir.ref<f32> |
| 16 |
! CHECK-DAG: fir.address_of(@_QMm2Ey) : !fir.ref<!fir.array<100xi32>> |
| 17 |
foo = x + y(1) |
| 18 |
end function |
| 19 |
end module |
| 20 |
! CHECK-LABEL: func @_QPm2use() |
| 21 |
real function m2use() |
| 22 |
use m2 |
| 23 |
! CHECK-DAG: fir.address_of(@_QMm2Ex) : !fir.ref<f32> |
| 24 |
! CHECK-DAG: fir.address_of(@_QMm2Ey) : !fir.ref<!fir.array<100xi32>> |
| 25 |
m2use = x + y(1) |
| 26 |
end function |
| 27 |
! Test renaming |
| 28 |
! CHECK-LABEL: func @_QPm2use_rename() |
| 29 |
real function m2use_rename() |
| 30 |
use m2, only: renamedx => x |
| 31 |
! CHECK-DAG: fir.address_of(@_QMm2Ex) : !fir.ref<f32> |
| 32 |
m2use_rename = renamedx |
| 33 |
end function |
| 34 |
|
| 35 |
! Module modEq2 defines data that is equivalenced |
| 36 |
module modEq2 |
| 37 |
! Equivalence, no initialization |
| 38 |
real :: x1(10), x2(10), x3(10) |
| 39 |
! Equivalence with initialization |
| 40 |
real :: y1 = 42. |
| 41 |
real :: y2(10) |
| 42 |
equivalence (x1(1), x2(5), x3(10)), (y1, y2(5)) |
| 43 |
contains |
| 44 |
! CHECK-LABEL: func @_QMmodeq2Pfoo() |
| 45 |
real function foo() |
| 46 |
! CHECK-DAG: fir.address_of(@_QMmodeq2Ex1) : !fir.ref<!fir.array<76xi8>> |
| 47 |
! CHECK-DAG: fir.address_of(@_QMmodeq2Ey1) : !fir.ref<!fir.array<10xi32>> |
| 48 |
foo = x2(1) + y1 |
| 49 |
end function |
| 50 |
end module |
| 51 |
! CHECK-LABEL: func @_QPmodeq2use() |
| 52 |
real function modEq2use() |
| 53 |
use modEq2 |
| 54 |
! CHECK-DAG: fir.address_of(@_QMmodeq2Ex1) : !fir.ref<!fir.array<76xi8>> |
| 55 |
! CHECK-DAG: fir.address_of(@_QMmodeq2Ey1) : !fir.ref<!fir.array<10xi32>> |
| 56 |
modEq2use = x2(1) + y1 |
| 57 |
end function |
| 58 |
! Test rename of used equivalence members |
| 59 |
! CHECK-LABEL: func @_QPmodeq2use_rename() |
| 60 |
real function modEq2use_rename() |
| 61 |
use modEq2, only: renamedx => x2, renamedy => y1 |
| 62 |
! CHECK-DAG: fir.address_of(@_QMmodeq2Ex1) : !fir.ref<!fir.array<76xi8>> |
| 63 |
! CHECK-DAG: fir.address_of(@_QMmodeq2Ey1) : !fir.ref<!fir.array<10xi32>> |
| 64 |
modEq2use = renamedx(1) + renamedy |
| 65 |
end function |
| 66 |
|
| 67 |
|
| 68 |
! Module defines variable in common block |
| 69 |
module modCommon2 |
| 70 |
! Module variable is in blank common |
| 71 |
real :: x_blank |
| 72 |
common // x_blank |
| 73 |
! Module variable is in named common, no init |
| 74 |
real :: x_named1(10) |
| 75 |
common /named1/ x_named1 |
| 76 |
! Module variable is in named common, with init |
| 77 |
integer :: i_named2 = 42 |
| 78 |
common /named2/ i_named2 |
| 79 |
contains |
| 80 |
! CHECK-LABEL: func @_QMmodcommon2Pfoo() |
| 81 |
real function foo() |
| 82 |
! CHECK-DAG: fir.address_of(@named2_) : !fir.ref<tuple<i32>> |
| 83 |
! CHECK-DAG: fir.address_of(@__BLNK__) : !fir.ref<!fir.array<4xi8>> |
| 84 |
! CHECK-DAG: fir.address_of(@named1_) : !fir.ref<!fir.array<40xi8>> |
| 85 |
foo = x_blank + x_named1(5) + i_named2 |
| 86 |
end function |
| 87 |
end module |
| 88 |
! CHECK-LABEL: func @_QPmodcommon2use() |
| 89 |
real function modCommon2use() |
| 90 |
use modCommon2 |
| 91 |
! CHECK-DAG: fir.address_of(@named2_) : !fir.ref<tuple<i32>> |
| 92 |
! CHECK-DAG: fir.address_of(@__BLNK__) : !fir.ref<!fir.array<4xi8>> |
| 93 |
! CHECK-DAG: fir.address_of(@named1_) : !fir.ref<!fir.array<40xi8>> |
| 94 |
modCommon2use = x_blank + x_named1(5) + i_named2 |
| 95 |
end function |
| 96 |
! CHECK-LABEL: func @_QPmodcommon2use_rename() |
| 97 |
real function modCommon2use_rename() |
| 98 |
use modCommon2, only : renamed0 => x_blank, renamed1 => x_named1, renamed2 => i_named2 |
| 99 |
! CHECK-DAG: fir.address_of(@named2_) : !fir.ref<tuple<i32>> |
| 100 |
! CHECK-DAG: fir.address_of(@__BLNK__) : !fir.ref<!fir.array<4xi8>> |
| 101 |
! CHECK-DAG: fir.address_of(@named1_) : !fir.ref<!fir.array<40xi8>> |
| 102 |
modCommon2use_rename = renamed0 + renamed1(5) + renamed2 |
| 103 |
end function |
| 104 |
|
| 105 |
|
| 106 |
! Test that there are no conflicts between equivalence use associated and the ones |
| 107 |
! from the scope |
| 108 |
real function test_no_equiv_conflicts() |
| 109 |
use modEq2 |
| 110 |
! Same equivalences as in modEq2. Test that lowering does not mixes |
| 111 |
! up the equivalence based on the similar offset inside the scope. |
| 112 |
real :: x1l(10), x2l(10), x3l(10) |
| 113 |
real :: y1l = 42. |
| 114 |
real :: y2l(10) |
| 115 |
save :: x1l, x2l, x3l, y1l, y2l |
| 116 |
equivalence (x1l(1), x2l(5), x3l(10)), (y1l, y2l(5)) |
| 117 |
! CHECK-DAG: fir.address_of(@_QFtest_no_equiv_conflictsEx1l) : !fir.ref<!fir.array<76xi8>> |
| 118 |
! CHECK-DAG: fir.address_of(@_QFtest_no_equiv_conflictsEy1l) : !fir.ref<!fir.array<10xi32>> |
| 119 |
! CHECK-DAG: fir.address_of(@_QMmodeq2Ex1) : !fir.ref<!fir.array<76xi8>> |
| 120 |
! CHECK-DAG: fir.address_of(@_QMmodeq2Ey1) : !fir.ref<!fir.array<10xi32>> |
| 121 |
test_no_equiv_conflicts = x2(1) + y1 + x2l(1) + y1l |
| 122 |
end function |