[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / module-single-point-of-def.f90
blobdd899078db9d0d051a0775c6fe9b3cc61c9de4a1
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.
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
17 !--- definition-a.f90
19 ! Test definition of `atype` derived type descriptor as `linkonce_odr`
20 module define_a
21 type atype
22 real :: x
23 end type
24 end module
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: }
30 !--- definition-b.f90
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.
35 module 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
42 end module
44 ! CHECK-B-DEF: fir.global @_QMdefine_bEi : i32 {
45 ! CHECK-B-DEF: fir.has_value %{{.*}} : i32
46 ! CHECK-B-DEF: }
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: }
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: }
58 !--- use.f90
60 ! Test define_b `i` is declared but not defined here and that derived types
61 ! descriptors are fully defined as linkonce_odr here.
62 subroutine foo()
63 use :: define_b
64 type(btype) :: somet
65 print *, somet
66 write(*, some_namelist)
67 end subroutine
68 ! CHECK-USE: fir.global @_QMdefine_bEi : i32{{$}}
69 ! CHECK-USE-NOT: fir.has_value %{{.*}} : i32
71 ! CHECK-USE: fir.global linkonce_odr @_QMdefine_aE.dt.atype constant : !fir.type<{{.*}}> {
72 ! CHECK-USE: fir.has_value
73 ! CHECK-USE: }
75 ! CHECK-USE: fir.global linkonce_odr @_QMdefine_bE.dt.btype constant : !fir.type<{{.*}}> {
76 ! CHECK-USE: fir.has_value
77 ! CHECK-USE: }