annotate gcc/testsuite/ada/acats/tests/c7/c761002.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- C761002.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that objects of a controlled type that are created
kono
parents:
diff changeset
28 -- by an allocator are finalized at the appropriate time. In
kono
parents:
diff changeset
29 -- particular, check that such objects are not finalized due to
kono
parents:
diff changeset
30 -- completion of the master in which they were allocated if the
kono
parents:
diff changeset
31 -- corresponding access type is declared outside of that master.
kono
parents:
diff changeset
32 --
kono
parents:
diff changeset
33 -- Check that Unchecked_Deallocation of a controlled
kono
parents:
diff changeset
34 -- object causes finalization of that object.
kono
parents:
diff changeset
35 --
kono
parents:
diff changeset
36 -- TEST DESCRIPTION:
kono
parents:
diff changeset
37 -- This test derives a type from Ada.Finalization.Controlled, and
kono
parents:
diff changeset
38 -- declares access types to that type in various scope scenarios.
kono
parents:
diff changeset
39 -- The dispatching procedure Finalize is redefined for the derived
kono
parents:
diff changeset
40 -- type to perform a check that it has been called at the
kono
parents:
diff changeset
41 -- correct time. This is accomplished using a global variable
kono
parents:
diff changeset
42 -- which indicates what state the software is currently
kono
parents:
diff changeset
43 -- executing. The test utilizes the TCTouch facilities to
kono
parents:
diff changeset
44 -- verify that Finalize is called the correct number of times, at
kono
parents:
diff changeset
45 -- the correct times. Several calls are made to validate passing
kono
parents:
diff changeset
46 -- the null string to check that Finalize has NOT been called at
kono
parents:
diff changeset
47 -- that point.
kono
parents:
diff changeset
48 --
kono
parents:
diff changeset
49 --
kono
parents:
diff changeset
50 -- CHANGE HISTORY:
kono
parents:
diff changeset
51 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
52 --
kono
parents:
diff changeset
53 --!
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 with Ada.Finalization;
kono
parents:
diff changeset
56 package C761002_0 is
kono
parents:
diff changeset
57 type Global is new Ada.Finalization.Controlled with null record;
kono
parents:
diff changeset
58 procedure Finalize( It: in out Global );
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 type Second is new Ada.Finalization.Limited_Controlled with null record;
kono
parents:
diff changeset
61 procedure Finalize( It: in out Second );
kono
parents:
diff changeset
62 end C761002_0;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 with Report;
kono
parents:
diff changeset
65 with TCTouch;
kono
parents:
diff changeset
66 package body C761002_0 is
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 procedure Finalize( It: in out Global ) is
kono
parents:
diff changeset
69 begin
kono
parents:
diff changeset
70 TCTouch.Touch('F'); ------------------------------------------------- F
kono
parents:
diff changeset
71 end Finalize;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 procedure Finalize( It: in out Second ) is
kono
parents:
diff changeset
74 begin
kono
parents:
diff changeset
75 TCTouch.Touch('S'); ------------------------------------------------- S
kono
parents:
diff changeset
76 end Finalize;
kono
parents:
diff changeset
77 end C761002_0;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 with Report;
kono
parents:
diff changeset
80 with TCTouch;
kono
parents:
diff changeset
81 with C761002_0;
kono
parents:
diff changeset
82 with Unchecked_Deallocation;
kono
parents:
diff changeset
83 procedure C761002 is
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 -- check the straightforward case
kono
parents:
diff changeset
86 procedure Subtest_1 is
kono
parents:
diff changeset
87 type Access_1 is access C761002_0.Global;
kono
parents:
diff changeset
88 V1 : Access_1;
kono
parents:
diff changeset
89 procedure Allocate is
kono
parents:
diff changeset
90 V2 : Access_1;
kono
parents:
diff changeset
91 begin
kono
parents:
diff changeset
92 V2 := new C761002_0.Global;
kono
parents:
diff changeset
93 V1 := V2; -- "dead" assignment must not be optimized away due to
kono
parents:
diff changeset
94 -- finalization "side effects", many more of these follow
kono
parents:
diff changeset
95 end Allocate;
kono
parents:
diff changeset
96 begin
kono
parents:
diff changeset
97 Allocate;
kono
parents:
diff changeset
98 -- no calls to Finalize should have occurred at this point
kono
parents:
diff changeset
99 TCTouch.Validate("","Allocated nested, retained");
kono
parents:
diff changeset
100 end Subtest_1;
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 -- check Unchecked_Deallocation
kono
parents:
diff changeset
103 procedure Subtest_2 is
kono
parents:
diff changeset
104 type Access_2 is access C761002_0.Global;
kono
parents:
diff changeset
105 procedure Free is
kono
parents:
diff changeset
106 new Unchecked_Deallocation(C761002_0.Global, Access_2);
kono
parents:
diff changeset
107 V1 : Access_2;
kono
parents:
diff changeset
108 V2 : Access_2;
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 procedure Allocate is
kono
parents:
diff changeset
111 begin
kono
parents:
diff changeset
112 V1 := new C761002_0.Global;
kono
parents:
diff changeset
113 V2 := new C761002_0.Global;
kono
parents:
diff changeset
114 end Allocate;
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 begin
kono
parents:
diff changeset
117 Allocate;
kono
parents:
diff changeset
118 -- no calls to Finalize should have occurred at this point.
kono
parents:
diff changeset
119 TCTouch.Validate("","Allocated nested, non-local");
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 Free(V1); -- instance of Unchecked_Deallocation
kono
parents:
diff changeset
122 -- should cause the finalization of V1.all
kono
parents:
diff changeset
123 TCTouch.Validate("F","Unchecked Deallocation");
kono
parents:
diff changeset
124 end Subtest_2; -- leaving this scope should cause the finalization of V2.all
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 -- check various master-exit scenarios
kono
parents:
diff changeset
127 -- the "Fake" parameters are used to avoid unwanted optimizations
kono
parents:
diff changeset
128 procedure Subtest_3 is
kono
parents:
diff changeset
129 procedure With_Local_Block is
kono
parents:
diff changeset
130 type Access_3 is access C761002_0.Global;
kono
parents:
diff changeset
131 V1 : Access_3;
kono
parents:
diff changeset
132 begin
kono
parents:
diff changeset
133 declare
kono
parents:
diff changeset
134 V2 : Access_3 := new C761002_0.Global;
kono
parents:
diff changeset
135 begin
kono
parents:
diff changeset
136 V1 := V2;
kono
parents:
diff changeset
137 end;
kono
parents:
diff changeset
138 TCTouch.Validate("","Local Block, normal exit");
kono
parents:
diff changeset
139 -- the allocated object should be finalized on leaving this scope
kono
parents:
diff changeset
140 end With_Local_Block;
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 procedure With_Local_Block_Return(Fake: Integer) is
kono
parents:
diff changeset
143 type Access_4 is access C761002_0.Global;
kono
parents:
diff changeset
144 V1 : Access_4 := new C761002_0.Global;
kono
parents:
diff changeset
145 begin
kono
parents:
diff changeset
146 if Fake = 0 then
kono
parents:
diff changeset
147 declare
kono
parents:
diff changeset
148 V2 : Access_4;
kono
parents:
diff changeset
149 begin
kono
parents:
diff changeset
150 V2 := new C761002_0.Global;
kono
parents:
diff changeset
151 return; -- the two allocated objects should be finalized
kono
parents:
diff changeset
152 end; -- upon leaving this scope
kono
parents:
diff changeset
153 else
kono
parents:
diff changeset
154 V1 := null;
kono
parents:
diff changeset
155 end if;
kono
parents:
diff changeset
156 end With_Local_Block_Return;
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 procedure With_Goto(Fake: Integer) is
kono
parents:
diff changeset
159 type Access_5 is access C761002_0.Global;
kono
parents:
diff changeset
160 V1 : Access_5 := new C761002_0.Global;
kono
parents:
diff changeset
161 V2 : Access_5;
kono
parents:
diff changeset
162 V3 : Access_5;
kono
parents:
diff changeset
163 begin
kono
parents:
diff changeset
164 if Fake = 0 then
kono
parents:
diff changeset
165 declare
kono
parents:
diff changeset
166 type Access_6 is access C761002_0.Second;
kono
parents:
diff changeset
167 V6 : Access_6;
kono
parents:
diff changeset
168 begin
kono
parents:
diff changeset
169 V6 := new C761002_0.Second;
kono
parents:
diff changeset
170 goto check;
kono
parents:
diff changeset
171 end;
kono
parents:
diff changeset
172 else
kono
parents:
diff changeset
173 V2 := V1;
kono
parents:
diff changeset
174 end if;
kono
parents:
diff changeset
175 V3 := V2;
kono
parents:
diff changeset
176 <<check>>
kono
parents:
diff changeset
177 TCTouch.Validate("S","goto past master end");
kono
parents:
diff changeset
178 end With_Goto;
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 begin
kono
parents:
diff changeset
181 With_Local_Block;
kono
parents:
diff changeset
182 TCTouch.Validate("F","Local Block, normal exit, after master");
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 With_Local_Block_Return( Report.Ident_Int(0) );
kono
parents:
diff changeset
185 TCTouch.Validate("FF","Local Block, return from block");
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 With_Goto( Report.Ident_Int(0) );
kono
parents:
diff changeset
188 TCTouch.Validate("F","With Goto");
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 end Subtest_3;
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 procedure Subtest_4 is
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 Oops : exception;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 procedure Alley( Fake: Integer ) is
kono
parents:
diff changeset
197 type Access_1 is access C761002_0.Global;
kono
parents:
diff changeset
198 V1 : Access_1;
kono
parents:
diff changeset
199 begin
kono
parents:
diff changeset
200 V1 := new C761002_0.Global;
kono
parents:
diff changeset
201 if Fake = 1 then
kono
parents:
diff changeset
202 raise Oops;
kono
parents:
diff changeset
203 end if;
kono
parents:
diff changeset
204 V1 := null;
kono
parents:
diff changeset
205 end Alley;
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 begin
kono
parents:
diff changeset
208 Catch: begin
kono
parents:
diff changeset
209 Alley( Report.Ident_Int(1) );
kono
parents:
diff changeset
210 exception
kono
parents:
diff changeset
211 when Oops => TCTouch.Validate("F","leaving via exception");
kono
parents:
diff changeset
212 when others => Report.Failed("Wrong exception");
kono
parents:
diff changeset
213 end Catch;
kono
parents:
diff changeset
214 end Subtest_4;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 begin -- Main test procedure.
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 Report.Test ("C761002", "Check that objects of a controlled type created "
kono
parents:
diff changeset
219 & "by an allocator are finalized appropriately. "
kono
parents:
diff changeset
220 & "Check that Unchecked_Deallocation of a "
kono
parents:
diff changeset
221 & "controlled object causes finalization "
kono
parents:
diff changeset
222 & "of that object" );
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 Subtest_1;
kono
parents:
diff changeset
225 -- leaving the scope of the access type should finalize the
kono
parents:
diff changeset
226 -- collection
kono
parents:
diff changeset
227 TCTouch.Validate("F","Allocated nested, Subtest 1");
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 Subtest_2;
kono
parents:
diff changeset
230 -- Unchecked_Deallocation already finalized one of the two
kono
parents:
diff changeset
231 -- objects allocated, the other should be the only one finalized
kono
parents:
diff changeset
232 -- at leaving the scope of the access type.
kono
parents:
diff changeset
233 TCTouch.Validate("F","Allocated non-local");
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 Subtest_3;
kono
parents:
diff changeset
236 -- there should be no remaining finalizations from this subtest
kono
parents:
diff changeset
237 TCTouch.Validate("","Localized objects");
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 Subtest_4;
kono
parents:
diff changeset
240 -- there should be no remaining finalizations from this subtest
kono
parents:
diff changeset
241 TCTouch.Validate("","Exception testing");
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 Report.Result;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 end C761002;