1! Test that module variables with an initializer are only defined once, 2! except for compiler generated derived type descriptor that should be 3! always fully defined as linkonce_odr by the compilation units defining or 4! using them. 5! Test that this holds true in contexts with namelist members that are special 6! because the symbol on the use site are not symbols with semantics::UseDetails, 7! but directly the symbols from the module scope. 8 9 10! RUN: split-file %s %t 11! RUN: bbc -emit-fir %t/definition-a.f90 -o - | FileCheck %s --check-prefix=CHECK-A-DEF 12! RUN: bbc -emit-fir %t/definition-b.f90 -o - | FileCheck %s --check-prefix=CHECK-B-DEF 13! RUN: bbc -emit-fir %t/use.f90 -o - | FileCheck %s --check-prefix=CHECK-USE 14 15 16 17!--- definition-a.f90 18 19! Test definition of `atype` derived type descriptor as `linkonce_odr` 20module define_a 21 type atype 22 real :: x 23 end type 24end module 25 26! CHECK-A-DEF: fir.global linkonce_odr @_QMdefine_aE.dt.atype constant target : !fir.type<{{.*}}> { 27! CHECK-A-DEF: fir.has_value 28! CHECK-A-DEF: } 29 30!--- definition-b.f90 31 32! Test define_b `i` is defined here. 33! Also test that the derived type descriptor of types defined here (`btype`) and used 34! here (`atype`) are fully defined here as linkonce_odr. 35module define_b 36 use :: define_a 37 type btype 38 type(atype) :: atype 39 end type 40 integer :: i = 42 41 namelist /some_namelist/ i 42end module 43 44! CHECK-B-DEF: fir.global @_QMdefine_bEi : i32 { 45! CHECK-B-DEF: fir.has_value %{{.*}} : i32 46! CHECK-B-DEF: } 47 48! CHECK-B-DEF: fir.global linkonce_odr @_QMdefine_bE.dt.btype constant target : !fir.type<{{.*}}> { 49! CHECK-B-DEF: fir.has_value 50! CHECK-B-DEF: } 51 52! CHECK-B-DEF: fir.global linkonce_odr @_QMdefine_aE.dt.atype constant : !fir.type<{{.*}}> { 53! CHECK-B-DEF: fir.has_value 54! CHECK-B-DEF: } 55 56 57 58!--- use.f90 59 60! Test define_b `i` is declared but not defined here and that derived types 61! descriptors are fully defined as linkonce_odr here. 62subroutine foo() 63 use :: define_b 64 type(btype) :: somet 65 print *, somet 66 write(*, some_namelist) 67end subroutine 68! CHECK-USE: fir.global @_QMdefine_bEi : i32{{$}} 69! CHECK-USE-NOT: fir.has_value %{{.*}} : i32 70 71! CHECK-USE: fir.global linkonce_odr @_QMdefine_aE.dt.atype constant : !fir.type<{{.*}}> { 72! CHECK-USE: fir.has_value 73! CHECK-USE: } 74 75! CHECK-USE: fir.global linkonce_odr @_QMdefine_bE.dt.btype constant : !fir.type<{{.*}}> { 76! CHECK-USE: fir.has_value 77! CHECK-USE: } 78 79