3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
27 -- Check that, for X'Access of a general access type A, Program_Error is
28 -- raised if the accessibility level of X is deeper than that of A.
29 -- Check for the case where X denotes a view that is a dereference of an
30 -- access parameter, or a rename thereof. Check for the case where X is
31 -- an access parameter and the corresponding actual is another access
35 -- In order to satisfy accessibility requirements, the designated
36 -- object X must be at the same or a less deep nesting level than the
37 -- general access type A -- X must "live" as long as A. Nesting
38 -- levels are the run-time nestings of masters: block statements;
39 -- subprogram, task, and entry bodies; and accept statements. Packages
40 -- are invisible to accessibility rules.
42 -- This test declares subprograms with access parameters, within which
43 -- 'Access is attempted on a dereference of an access parameter, and
44 -- assigned to an access object whose type A is declared at some nesting
45 -- level. The test verifies that Program_Error is raised if the actual
46 -- corresponding to the access parameter is another access parameter,
47 -- and the actual corresponding to this second access parameter is:
49 -- (1) an expression of a named access type, and the accessibility
50 -- level of the named access type is deeper than that of the
53 -- (2) a reference to the Access attribute (e.g., X'Access), and
54 -- the accessibility level of X is deeper than that of the
57 -- Note that the static nesting level of the actual corresponding to the
58 -- access parameter can be deeper than that of the type A -- it is
59 -- the run-time nesting that matters for accessibility rules. Consider
60 -- the case where the access type A is declared within the called
61 -- subprogram. The accessibility check will never fail, even if the
62 -- actual happens to have a deeper static nesting level:
64 -- procedure P (X: access T) is
65 -- type A is access all T; -- Static level = 2, e.g.
66 -- Acc : A := X.all'Access; -- Check should never fail.
69 -- procedure Q (Y: access T) is
75 -- Actual : aliased T; -- Static level = 3, e.g.
80 -- For the execution of Q (and hence P), the accessibility level of
81 -- type A will always be deeper than that of Actual, so there is no
82 -- danger of a dangling reference arising from the assignment to
83 -- Acc. Thus, X.all'Access is safe, even though the static nesting
84 -- level of Actual is deeper than that of A.
88 -- 06 Dec 94 SAIC ACVC 2.0
89 -- 15 Jul 98 EDS Avoid optimization.
90 -- 28 Jun 02 RLB Added pragma Elaborate_All (Report);.
93 with report
; use report
; pragma Elaborate_All
(report
);
96 type Desig
is array (1 .. 10) of Integer;
98 X0
: aliased Desig
:= (Desig
'Range => Ident_Int
(3)); -- Level = 0.
100 type Acc_L0
is access all Desig
; -- Level = 0.
103 type Result_Kind
is (OK
, P_E
, O_E
);
105 procedure Target_Is_Level_0_Nest
(Y
: access Desig
; S
: out Result_Kind
);
106 procedure Never_Fails_Nest
(Y
: access Desig
; S
: out Result_Kind
);
107 procedure Never_Fails_Same
(Y
: access Desig
; S
: out Result_Kind
);
112 --==================================================================--
115 package body C3A2003_0
is
117 procedure Target_Is_Level_0_Nest
(Y
: access Desig
; S
: out Result_Kind
) is
120 -- This procedure utilizes 'Access on a dereference of an access
121 -- parameter, and assigned to an access object whose type A is
122 -- declared at some nesting level. Program_Error is raised if
123 -- the accessibility level of the operand type is deeper than that
124 -- of the target type.
126 procedure Nested
(X
: access Desig
; R
: out Result_Kind
) is
127 -- Dereference of an access_to_object value is aliased.
128 Ren
: Desig
renames X
.all; -- Renaming of a dereference
129 begin -- of an access parameter.
130 -- The accessibility level of type A0 is 0.
134 when Program_Error
=>
140 begin -- Target_Is_Level_0_Nest
142 end Target_Is_Level_0_Nest
;
144 ------------------------------------------------------------------
146 procedure Never_Fails_Nest
(Y
: access Desig
; S
: out Result_Kind
) is
148 type Acc_Deeper
is access all Desig
;
151 function Nested
(X
: access Desig
) return Result_Kind
is
153 -- X.all'Access below will always be safe, since the accessibility
154 -- level (although not necessarily the static nesting depth) of the
155 -- type of AD will always be deeper than or the same as that of the
156 -- actual corresponding to Y.
158 if Ident_Int
(AD
(4)) /= 3 then --Avoid Optimization of AD
159 FAILED
("Initial Values not correct.");
163 when Program_Error
=>
169 begin -- Never_Fails_Nest
171 end Never_Fails_Nest
;
173 ------------------------------------------------------------------
175 procedure Called_By_Never_Fails_Same
176 (X
: access Desig
; R
: out Result_Kind
) is
177 type Acc_Local
is access all Desig
;
180 -- Dereference of an access_to_object value is aliased.
181 Ren
: Desig
renames X
.all; -- Renaming of a dereference
182 begin -- of an access parameter.
183 -- Ren'Access below will always be safe, since the accessibility
184 -- level (although not necessarily the static nesting depth) of
185 -- type of AL will always be deeper than or the same as that of the
186 -- actual corresponding to Y.
188 if Ident_Int
(AL
(4)) /= 3 then --Avoid Optimization of AL
189 FAILED
("Initial Values not correct.");
193 when Program_Error
=>
197 end Called_By_Never_Fails_Same
;
199 ------------------------------------------------------------------
201 procedure Never_Fails_Same
(Y
: access Desig
; S
: out Result_Kind
) is
203 Called_By_Never_Fails_Same
(Y
, S
);
204 end Never_Fails_Same
;
209 --==================================================================--
215 with Report
; use report
;
219 type Acc_L1
is access all Desig
; -- Level = 1.
221 X1
: aliased Desig
:= (Desig
'Range => Ident_Int
(3));
225 procedure Called_By_Target_L1
(X
: access Desig
; R
: out Result_Kind
) is
227 -- The accessibility level of the type of A1 is 1.
229 if IDENT_INT
(A1
(4)) /= 3 then --Avoid optimization of A1
230 FAILED
("Initial values not correct.");
234 when Program_Error
=>
238 end Called_By_Target_L1
;
240 ------------------------------------------------------------------
242 function Target_Is_Level_1_Same
(Y
: access Desig
) return Result_Kind
is
245 Called_By_Target_L1
(Y
, S
);
247 end Target_Is_Level_1_Same
;
249 ------------------------------------------------------------------
251 procedure Display_Results
(Result
: in Result_Kind
;
252 Expected
: in Result_Kind
;
255 if Result
/= Expected
then
257 when OK
=> Report
.Failed
("No exception raised: " & Msg
);
258 when P_E
=> Report
.Failed
("Program_Error raised: " & Msg
);
259 when O_E
=> Report
.Failed
("Unexpected exception raised: " & Msg
);
266 Report
.Test
("C3A2003", "Check that, for X'Access of general access " &
267 "type A, Program_Error is raised if the accessibility " &
268 "level of X is deeper than that of A: X is an access " &
269 "parameter; corresponding actual is another access " &
273 -- Accessibility level of actual is 0 (actual is X'Access):
275 Never_Fails_Same
(X0
'Access, Res
);
276 Display_Results
(Res
, OK
, "Never_Fails_Same, level 0 actual");
278 Never_Fails_Nest
(X0
'Access, Res
);
279 Display_Results
(Res
, OK
, "Target_L1_Nest, level 0 actual");
281 Target_Is_Level_0_Nest
(X0
'Access, Res
);
282 Display_Results
(Res
, OK
, "Target_L0_Nest, level 0 actual");
284 Res
:= Target_Is_Level_1_Same
(X0
'Access);
285 Display_Results
(Res
, OK
, "Target_L1_Same, level 0 actual");
288 -- Accessibility level of actual is 1 (actual is X'Access):
290 Never_Fails_Same
(X1
'Access, Res
);
291 Display_Results
(Res
, OK
, "Never_Fails_Same, level 1 actual");
293 Never_Fails_Nest
(X1
'Access, Res
);
294 Display_Results
(Res
, OK
, "Target_L1_Nest, level 1 actual");
296 Target_Is_Level_0_Nest
(X1
'Access, Res
);
297 Display_Results
(Res
, P_E
, "Target_L0_Nest, level 1 actual");
299 Res
:= Target_Is_Level_1_Same
(X1
'Access);
300 Display_Results
(Res
, OK
, "Target_L1_Same, level 1 actual");
305 X2
: aliased Desig
:= (Desig
'Range => Ident_Int
(3));
306 type Acc_L2
is access all Desig
; -- Level = 2.
307 Expr_L2
: Acc_L2
:= X2
'Access;
310 -- Accessibility level of actual is 2 (actual is expression of named
313 Never_Fails_Same
(Expr_L2
, Res
);
314 Display_Results
(Res
, OK
, "Never_Fails_Same, level 2 actual");
316 Never_Fails_Nest
(Expr_L2
, Res
);
317 Display_Results
(Res
, OK
, "Target_L1_Nest, level 2 actual");
319 Target_Is_Level_0_Nest
(Expr_L2
, Res
);
320 Display_Results
(Res
, P_E
, "Target_L0_Nest, level 2 actual");
322 Res
:= Target_Is_Level_1_Same
(Expr_L2
);
323 Display_Results
(Res
, P_E
, "Target_L1_Same, level 2 actual");