1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
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
8 ! Module m2 defines simple data
13 ! CHECK-LABEL: func @_QMm2Pfoo()
15 ! CHECK-DAG: fir.address_of(@_QMm2Ex) : !fir.ref<f32>
16 ! CHECK-DAG: fir.address_of(@_QMm2Ey) : !fir.ref<!fir.array<100xi32>>
20 ! CHECK-LABEL: func @_QPm2use()
23 ! CHECK-DAG: fir.address_of(@_QMm2Ex) : !fir.ref<f32>
24 ! CHECK-DAG: fir.address_of(@_QMm2Ey) : !fir.ref<!fir.array<100xi32>>
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
35 ! Module modEq2 defines data that is equivalenced
37 ! Equivalence, no initialization
38 real :: x1(10), x2(10), x3(10)
39 ! Equivalence with initialization
42 equivalence (x1(1), x2(5), x3(10)), (y1
, y2(5))
44 ! CHECK-LABEL: func @_QMmodeq2Pfoo()
46 ! CHECK-DAG: fir.address_of(@_QMmodeq2Ex1) : !fir.ref<!fir.array<76xi8>>
47 ! CHECK-DAG: fir.address_of(@_QMmodeq2Ey1) : !fir.ref<!fir.array<10xi32>>
51 ! CHECK-LABEL: func @_QPmodeq2use()
52 real function modEq2use()
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
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
68 ! Module defines variable in common block
70 ! Module variable is in blank common
73 ! Module variable is in named common, no init
75 common /named1
/ x_named1
76 ! Module variable is in named common, with init
77 integer :: i_named2
= 42
78 common /named2
/ i_named2
80 ! CHECK-LABEL: func @_QMmodcommon2Pfoo()
82 ! CHECK-DAG: fir.address_of(@_QBnamed2) : !fir.ref<tuple<i32>>
83 ! CHECK-DAG: fir.address_of(@_QB) : !fir.ref<!fir.array<4xi8>>
84 ! CHECK-DAG: fir.address_of(@_QBnamed1) : !fir.ref<!fir.array<40xi8>>
85 foo
= x_blank
+ x_named1(5) + i_named2
88 ! CHECK-LABEL: func @_QPmodcommon2use()
89 real function modCommon2use()
91 ! CHECK-DAG: fir.address_of(@_QBnamed2) : !fir.ref<tuple<i32>>
92 ! CHECK-DAG: fir.address_of(@_QB) : !fir.ref<!fir.array<4xi8>>
93 ! CHECK-DAG: fir.address_of(@_QBnamed1) : !fir.ref<!fir.array<40xi8>>
94 modCommon2use
= x_blank
+ x_named1(5) + i_named2
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(@_QBnamed2) : !fir.ref<tuple<i32>>
100 ! CHECK-DAG: fir.address_of(@_QB) : !fir.ref<!fir.array<4xi8>>
101 ! CHECK-DAG: fir.address_of(@_QBnamed1) : !fir.ref<!fir.array<40xi8>>
102 modCommon2use_rename
= renamed0
+ renamed1(5) + renamed2
106 ! Test that there are no conflicts between equivalence use associated and the ones
108 real function test_no_equiv_conflicts()
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)
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