[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / equivalence-1.f90
blob17b10eaa18ecb900c5dd3117f235b5a0bac553ef
1 ! RUN: bbc -o - %s | FileCheck %s
3 ! CHECK-LABEL: func @_QPs1
4 SUBROUTINE s1
5 INTEGER i
6 REAL r
7 ! CHECK: = fir.alloca !fir.array<4xi8> {uniq_name = "_QFs1Ei"}
8 EQUIVALENCE (r,i)
9 ! CHECK: %[[coor:.*]] = fir.coordinate_of %{{.*}}, %{{.*}} : (!fir.ref<!fir.array<4xi8>>, index) -> !fir.ref<i8>
10 ! CHECK: %[[iloc:.*]] = fir.convert %[[coor]] : (!fir.ref<i8>) -> !fir.ptr<i32>
11 ! CHECK-DAG: fir.store %{{.*}} to %[[iloc]] : !fir.ptr<i32>
12 i = 4
13 ! CHECK-DAG: %[[floc:.*]] = fir.convert %[[coor]] : (!fir.ref<i8>) -> !fir.ptr<f32>
14 ! CHECK: %[[ld:.*]] = fir.load %[[floc]] : !fir.ptr<f32>
15 PRINT *, r
16 END SUBROUTINE s1
18 ! CHECK-LABEL: func @_QPs2
19 SUBROUTINE s2
20 INTEGER i(10)
21 REAL r(10)
22 ! CHECK: %[[arr:.*]] = fir.alloca !fir.array<48xi8>
23 EQUIVALENCE (r(3),i(5))
24 ! CHECK: %[[iarr:.*]] = fir.convert %{{.*}} : (!fir.ref<i8>) -> !fir.ptr<!fir.array<10xi32>>
25 ! CHECK: %[[foff:.*]] = fir.coordinate_of %[[arr]], %{{.*}} : (!fir.ref<!fir.array<48xi8>>, index) -> !fir.ref<i8>
26 ! CHECK: %[[farr:.*]] = fir.convert %[[foff]] : (!fir.ref<i8>) -> !fir.ptr<!fir.array<10xf32>>
27 ! CHECK: %[[ia:.*]] = fir.coordinate_of %[[iarr]], %{{.*}} : (!fir.ptr<!fir.array<10xi32>>, i64) -> !fir.ref<i32>
28 ! CHECK: fir.store %{{.*}} to %[[ia]] : !fir.ref<i32>
29 i(5) = 18
30 ! CHECK: %[[fld:.*]] = fir.coordinate_of %[[farr]], %{{.*}} : (!fir.ptr<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
31 ! CHECK: = fir.load %[[fld]] : !fir.ref<f32>
32 PRINT *, r(3)
33 END SUBROUTINE s2
35 ! CHECK-LABEL: func @_QPs3
36 SUBROUTINE s3
37 REAL r(10)
38 TYPE t
39 SEQUENCE
40 REAL r(10)
41 END TYPE t
42 TYPE(t) x
43 ! CHECK: %[[group:.*]] = fir.alloca !fir.array<40xi8>
44 EQUIVALENCE (r,x)
45 ! CHECK: %[[coor:.*]] = fir.coordinate_of %[[group]], %c0 : (!fir.ref<!fir.array<40xi8>>, index) -> !fir.ref<i8>
46 ! CHECK: %[[rloc:.*]] = fir.convert %[[coor]] : (!fir.ref<i8>) -> !fir.ptr<!fir.array<10xf32>>
47 ! CHECK: %[[xloc:.*]] = fir.convert %[[coor]] : (!fir.ref<i8>) -> !fir.ptr<!fir.type<_QFs3Tt{r:!fir.array<10xf32>}>>
48 ! CHECK: %[[fidx:.*]] = fir.field_index r, !fir.type<_QFs3Tt{r:!fir.array<10xf32>}>
49 ! CHECK: %[[xrloc:.*]] = fir.coordinate_of %[[xloc]], %[[fidx]] :
50 ! CHECK: %[[v1loc:.*]] = fir.coordinate_of %[[xrloc]], %c8_i64 : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
51 ! CHECK: fir.store %{{.*}} to %[[v1loc]] : !fir.ref<f32>
52 x%r(9) = 9.0
53 ! CHECK: %[[v2loc:.*]] = fir.coordinate_of %[[rloc]], %c8_i64 : (!fir.ptr<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
54 ! CHECK: %{{.*}} = fir.load %[[v2loc]] : !fir.ref<f32>
55 PRINT *, r(9)
56 END SUBROUTINE s3
58 ! test that equivalence in main program containing arrays are placed in global memory.
59 ! CHECK: fir.global internal @_QFEa : !fir.array<400000000xi8>
60 integer :: a, b(100000000)
61 equivalence (a, b)
62 b(1) = 42
63 print *, a
65 CALL s1
66 CALL s2
67 CALL s3
68 END