123 lines · plain
1! RUN: bbc -emit-fir %s -o - | FileCheck %s2 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 the5! module being defined in this file. This require a front-end fix to be pushed first6! so7 8! Module m2 defines simple data9module m210 real :: x11 integer :: y(100)12contains13 ! 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 function19end module20! CHECK-LABEL: func @_QPm2use()21real function m2use()22 use m223 ! 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)26end function27! Test renaming28! CHECK-LABEL: func @_QPm2use_rename()29real function m2use_rename()30 use m2, only: renamedx => x31 ! CHECK-DAG: fir.address_of(@_QMm2Ex) : !fir.ref<f32>32 m2use_rename = renamedx33end function34 35! Module modEq2 defines data that is equivalenced36module modEq237 ! Equivalence, no initialization38 real :: x1(10), x2(10), x3(10)39 ! Equivalence with initialization40 real :: y1 = 42.41 real :: y2(10)42 equivalence (x1(1), x2(5), x3(10)), (y1, y2(5))43contains44 ! 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) + y149 end function50end module51! CHECK-LABEL: func @_QPmodeq2use()52real function modEq2use()53 use modEq254 ! 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) + y157end function58! Test rename of used equivalence members59! CHECK-LABEL: func @_QPmodeq2use_rename()60real function modEq2use_rename()61 use modEq2, only: renamedx => x2, renamedy => y162 ! 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) + renamedy65end function66 67 68! Module defines variable in common block69module modCommon270 ! Module variable is in blank common71 real :: x_blank72 common // x_blank73 ! Module variable is in named common, no init74 real :: x_named1(10)75 common /named1/ x_named176 ! Module variable is in named common, with init77 integer :: i_named2 = 4278 common /named2/ i_named279contains80 ! 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_named286 end function87end module88! CHECK-LABEL: func @_QPmodcommon2use()89real function modCommon2use()90 use modCommon291 ! 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_named295end function96! CHECK-LABEL: func @_QPmodcommon2use_rename()97real function modCommon2use_rename()98 use modCommon2, only : renamed0 => x_blank, renamed1 => x_named1, renamed2 => i_named299 ! 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) + renamed2103end function104 105 106! Test that there are no conflicts between equivalence use associated and the ones107! from the scope108real function test_no_equiv_conflicts()109 use modEq2110 ! Same equivalences as in modEq2. Test that lowering does not mixes111 ! 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, y2l116 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) + y1l122end function123