[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Semantics / data04.f90
blob777ddbf2d6b295d84a307cf3318feef5021e6df6
1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 !Testing data constraints : C876, C877
3 module m
4 integer :: first
5 contains
6 subroutine h
7 integer a,b
8 !C876
9 !ERROR: Host-associated object 'first' must not be initialized in a DATA statement
10 DATA first /1/
11 end subroutine
13 function g(i)
14 integer ::i
15 g = i *1024
16 end
18 function f(i)
19 integer ::i
20 integer ::result
21 integer, allocatable :: a
22 integer :: b(i)
23 character(len=i), pointer:: charPtr
24 character(len=i), allocatable:: charAlloc
25 !C876
26 !ERROR: Dummy argument 'i' must not be initialized in a DATA statement
27 DATA i /1/
28 !C876
29 !ERROR: Function result 'f' must not be initialized in a DATA statement
30 DATA f /1/
31 !C876
32 !ERROR: Procedure 'g' must not be initialized in a DATA statement
33 DATA g /1/
34 !C876
35 !ERROR: Allocatable 'a' must not be initialized in a DATA statement
36 DATA a /1/
37 !C876
38 !ERROR: Automatic variable 'b' must not be initialized in a DATA statement
39 DATA b(1) /1/
40 !C876
41 !Ok: As charPtr is a pointer, it is not an automatic object
42 DATA charPtr / NULL() /
43 !C876
44 !ERROR: Allocatable 'charalloc' must not be initialized in a DATA statement
45 DATA charAlloc / 'abc' /
46 f = i *1024
47 end
49 subroutine CheckObject(i)
50 type specialNumbers
51 integer one
52 integer numbers(5)
53 type(specialNumbers), pointer :: headOfTheList
54 integer, pointer, dimension(:) :: ptoarray
55 character, pointer, dimension(:) :: ptochar
56 end type
57 type large
58 integer, allocatable :: allocVal
59 integer, allocatable :: elt(:)
60 integer val
61 type(specialNumbers) numsArray(10)
62 end type
63 type(large) largeNumber
64 type(large), allocatable :: allocatableLarge
65 type(large) :: largeNumberArray(i)
66 type(large) :: largeArray(5)
67 character :: name(i)
68 type small
69 real :: x
70 end type
71 type(small), pointer :: sp
72 !This case is ok.
73 DATA(largeNumber % numsArray(j) % headOfTheList, j = 1, 10) / 10 * NULL() /
74 !C877
75 !ERROR: Data object must not contain pointer 'headofthelist' as a non-rightmost part
76 DATA(largeNumber % numsArray(j) % headOfTheList % one, j = 1, 10) / 10 * 1 /
77 !C877
78 !ERROR: Rightmost data object pointer 'ptoarray' must not be subscripted
79 DATA(largeNumber % numsArray(j) % ptoarray(1), j = 1, 10) / 10 * 1 /
80 !C877
81 !ERROR: Rightmost data object pointer 'ptochar' must not be subscripted
82 DATA largeNumber % numsArray(1) % ptochar(1:2) / 'ab' /
83 !C876
84 !ERROR: Allocatable 'elt' must not be initialized in a DATA statement
85 DATA(largeNumber % elt(j) , j = 1, 10) / 10 * 1/
86 !C876
87 !ERROR: Allocatable 'allocval' must not be initialized in a DATA statement
88 DATA(largeArray(j) % allocVal , j = 1, 10) / 10 * 1/
89 !C876
90 !ERROR: Allocatable 'allocatablelarge' must not be initialized in a DATA statement
91 DATA allocatableLarge % val / 1 /
92 !C876
93 !ERROR: Automatic variable 'largenumberarray' must not be initialized in a DATA statement
94 DATA(largeNumberArray(j) % val, j = 1, 10) / 10 * NULL() /
95 !C876
96 !ERROR: Automatic variable 'name' must not be initialized in a DATA statement
97 DATA name( : 2) / 'Ancd' /
98 !ERROR: Target of pointer 'sp' must not be initialized in a DATA statement
99 DATA sp%x / 1.0 /
103 block data foo
104 integer :: a,b
105 common /c/ a,b
106 !C876
107 !OK: Correct use
108 DATA a /1/
109 end block data
111 module m2
112 integer m2_i
113 type newType
114 integer number
115 end type
116 type(newType) m2_number1
117 contains
119 subroutine checkDerivedType(m2_number)
120 type(newType) m2_number
121 type(newType) m2_number3
122 !C876
123 !ERROR: Dummy argument 'm2_number' must not be initialized in a DATA statement
124 DATA m2_number%number /1/
125 !C876
126 !ERROR: Host-associated object 'm2_number1' must not be initialized in a DATA statement
127 DATA m2_number1%number /1/
128 !C876
129 !OK: m2_number3 is not associated through use association
130 DATA m2_number3%number /1/
134 program new
135 use m2
136 type(newType) m2_number2
137 !C876
138 !ERROR: USE-associated object 'm2_i' must not be initialized in a DATA statement
139 DATA m2_i /1/
140 !C876
141 !ERROR: USE-associated object 'm2_number1' must not be initialized in a DATA statement
142 DATA m2_number1%number /1/
143 !C876
144 !OK: m2_number2 is not associated through use association
145 DATA m2_number2%number /1/
146 end program