xref: /llvm-project/flang/test/Lower/constant-literal-mangling.f90 (revision f35f863a88f83332bef9605ef4cfe4f05c066efb)
1! Test the names created for globals holding constant literal values
2! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s
3
4type someType
5  integer :: i
6end type
7
8type otherType
9  integer :: i
10end type
11
12type emptyType1
13end type emptyType1
14
15type emptyType2
16end type emptyType2
17
18  print *, [42, 42]
19! CHECK: fir.address_of(@_QQro.2xi4.0)
20
21  print *, reshape([42, 42, 42, 42, 42, 42], [2,3])
22! CHECK: fir.address_of(@_QQro.2x3xi4.1)
23
24  print *, [42_8, 42_8]
25! CHECK: fir.address_of(@_QQro.2xi8.2)
26
27  print *, [0.42, 0.42]
28! CHECK: fir.address_of(@_QQro.2xr4.3)
29
30  print *, [0.42_8, 0.42_8]
31! CHECK: fir.address_of(@_QQro.2xr8.4)
32
33  print *, [.true.]
34! CHECK: fir.address_of(@_QQro.1xl4.5)
35
36  print *, [.true._8]
37! CHECK: fir.address_of(@_QQro.1xl8.6)
38
39  print *, [(1., -1.), (-1., 1)]
40! CHECK: fir.address_of(@_QQro.2xz4.7)
41
42  print *, [(1._8, -1._8), (-1._8, 1._8)]
43! CHECK: fir.address_of(@_QQro.2xz8.8)
44
45  print *, [someType(42), someType(43)]
46! CHECK: fir.address_of(@_QQro.2x_QFTsometype.9
47
48  ! Verify that literals of the same type/shape
49  ! are mapped to different global objects:
50  print *, [someType(11)]
51! CHECK: fir.address_of(@_QQro.1x_QFTsometype.10)
52  print *, [someType(42)]
53! CHECK: fir.address_of(@_QQro.1x_QFTsometype.11)
54  print *, [someType(11)]
55! CHECK: fir.address_of(@_QQro.1x_QFTsometype.10)
56  print *, [someType(42)]
57! CHECK: fir.address_of(@_QQro.1x_QFTsometype.11)
58  print *, [someType(11)]
59! CHECK: fir.address_of(@_QQro.1x_QFTsometype.10)
60  print *, [someType(42)]
61! CHECK: fir.address_of(@_QQro.1x_QFTsometype.11)
62  print *, [someType(11)]
63! CHECK: fir.address_of(@_QQro.1x_QFTsometype.10)
64  print *, [someType(42)]
65! CHECK: fir.address_of(@_QQro.1x_QFTsometype.11)
66
67  print *, [Character(4)::]
68! CHECK: fir.address_of(@_QQro.0x4xc1.null.12)
69  print *, [Character(2)::]
70! CHECK: fir.address_of(@_QQro.0x2xc1.null.13)
71  print *, [Character(2)::]
72! CHECK: fir.address_of(@_QQro.0x2xc1.null.13)
73
74  print *, [otherType(42)]
75! CHECK: fir.address_of(@_QQro.1x_QFTothertype.14)
76
77  print *, [emptyType1()]
78  print *, [emptyType2()]
79end
80
81! CHECK: fir.global internal @_QQro.1x_QFTsometype.10 constant : !fir.array<1x!fir.type<_QFTsometype{i:i32}>> {
82! CHECK:   %{{.*}} = arith.constant 11 : i32
83! CHECK: }
84
85! CHECK: fir.global internal @_QQro.1x_QFTsometype.11 constant : !fir.array<1x!fir.type<_QFTsometype{i:i32}>> {
86! CHECK:   %{{.*}} = arith.constant 42 : i32
87! CHECK: }
88
89! CHECK: fir.global internal @_QQro.0x4xc1.null.12 constant : !fir.array<0x!fir.char<1,4>> {
90! CHECK:   %[[T1:.*]] = fir.undefined !fir.array<0x!fir.char<1,4>>
91! CHECK:   fir.has_value %[[T1]] : !fir.array<0x!fir.char<1,4>>
92! CHECK: }
93
94! CHECK: fir.global internal @_QQro.0x2xc1.null.13 constant : !fir.array<0x!fir.char<1,2>> {
95! CHECK:   %[[T2:.*]] = fir.undefined !fir.array<0x!fir.char<1,2>>
96! CHECK:   fir.has_value %[[T2]] : !fir.array<0x!fir.char<1,2>>
97! CHECK: }
98
99! CHECK: fir.global internal @_QQro.1x_QFTothertype.14 constant : !fir.array<1x!fir.type<_QFTothertype{i:i32}>> {
100! CHECK:   %{{.*}} = arith.constant 42 : i32
101! CHECK: }
102