1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
-- CXH1001.A
--
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE
-- Check pragma Normalize_Scalars.
-- Check that this configuration pragma causes uninitialized scalar
-- objects to be set to a predictable value. Check that multiple
-- compilation units are affected. Check for uninitialized scalar
-- objects that are subcomponents of composite objects, unassigned
-- out parameters, objects that have been allocated without an initial
-- value, and objects that are stand alone.
--
-- TEST DESCRIPTION
-- The test requires that the configuration pragma Normalize_Scalars
-- be processed. It then defines a few scalar types (some enumeration,
-- some integer) in a few packages. The scalar types are designed such
-- that the representation will easily allow for an out of range value.
-- Unchecked_Conversion and the 'Valid attribute are both used to verify
-- that the default values of the various kinds of objects are indeed
-- invalid for the type.
--
-- Note that this test relies on having uninitialized objects, compilers
-- may generate several warnings to this effect.
--
-- SPECIAL REQUIREMENTS
-- The implementation must process configuration pragmas which
-- are not part of any Compilation Unit; the method employed
-- is implementation defined.
--
-- APPLICABILITY CRITERIA:
-- This test is only applicable for a compiler attempting validation
-- for the Safety and Security Annex.
--
--
-- CHANGE HISTORY:
-- 26 OCT 95 SAIC Initial version
-- 04 NOV 96 SAIC Added cases, upgraded commentary
--
--!
---------------------------- CONFIGURATION PRAGMAS -----------------------
pragma Normalize_Scalars; -- OK
-- configuration pragma
------------------------ END OF CONFIGURATION PRAGMAS --------------------
----------------------------------------------------------------- CXH1001_0
with Impdef.Annex_H;
with Unchecked_Conversion;
package CXH1001_0 is
package Imp_H renames Impdef.Annex_H;
use type Imp_H.Small_Number;
use type Imp_H.Scalar_To_Normalize;
Global_Object : Imp_H.Scalar_To_Normalize;
-- if the pragma is in effect, this should come up with the predictable
-- value
Global_Number : Imp_H.Small_Number;
-- if the pragma is in effect, this should come up with the predictable
-- value
procedure Package_Check;
type Num is range 0..2**Imp_H.Scalar_To_Normalize'Size-1;
for Num'Size use Imp_H.Scalar_To_Normalize'Size;
function STN_2_Num is
new Unchecked_Conversion( Imp_H.Scalar_To_Normalize, Num );
Small_Last : constant Integer := Integer(Imp_H.Small_Number'Last);
end CXH1001_0;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
with Report;
package body CXH1001_0 is
procedure Heap_Check( A_Value : access Imp_H.Scalar_To_Normalize;
A_Number : access Imp_H.Small_Number ) is
Value : Num;
Number : Integer;
begin
if A_Value.all'Valid then
Value := STN_2_Num ( A_Value.all );
if Imp_H.Default_For_Scalar_To_Normalize_Is_In_Range then
if Imp_H.Scalar_To_Normalize'Val(Value)
/= Imp_H.Default_For_Scalar_To_Normalize then
Report.Failed("Implicit initial value for local variable is not "
& "the predicted value");
end if;
else
if Value in 0 ..
Imp_H.Scalar_To_Normalize'Pos(Imp_H.Scalar_To_Normalize'Last) then
Report.Failed("Implicit initial value for local variable is a "
& "value of the type");
end if;
end if;
end if;
if A_Number.all'Valid then
Number := Integer( A_Number.all );
if Imp_H.Default_For_Small_Number_Is_In_Range then
if Global_Number /= Imp_H.Default_For_Small_Number then
Report.Failed("Implicit initial value for number is not "
& "the predicted value");
end if;
else
if Integer( Global_Number ) in 0 .. Report.Ident_Int(Small_Last) then
Report.Failed("Implicit initial value for number is a "
& "value of the type");
end if;
end if;
end if;
end Heap_Check;
procedure Package_Check is
Value : Num;
Number : Integer;
begin
if Global_Object'Valid then
Value := STN_2_Num ( Global_Object );
if Imp_H.Default_For_Scalar_To_Normalize_Is_In_Range then
if Imp_H.Scalar_To_Normalize'Val(Value)
/= Imp_H.Default_For_Scalar_To_Normalize then
Report.Failed("Implicit initial value for local variable is not "
& "the predicted value");
end if;
else
if Value in 0 ..
Imp_H.Scalar_To_Normalize'Pos(Imp_H.Scalar_To_Normalize'Last) then
Report.Failed("Implicit initial value for local variable is a "
& "value of the type");
end if;
end if;
end if;
if Global_Number'Valid then
Number := Integer( Global_Number );
if Imp_H.Default_For_Small_Number_Is_In_Range then
if Global_Number /= Imp_H.Default_For_Small_Number then
Report.Failed("Implicit initial value for number is not "
& "the predicted value");
end if;
else
if Integer( Global_Number ) in 0 .. Report.Ident_Int(Small_Last) then
Report.Failed("Implicit initial value for number is a "
& "value of the type");
end if;
end if;
end if;
Heap_Check( new Imp_H.Scalar_To_Normalize, new Imp_H.Small_Number );
end Package_Check;
end CXH1001_0;
----------------------------------------------------------------- CXH1001_1
with Unchecked_Conversion;
package CXH1001_0.CXH1001_1 is
-- kill as many birds as possible with a single stone:
-- embed a protected object in the body of a child package,
-- checks the multiple compilation unit case,
-- and part of the subcomponent case.
protected Thingy is
procedure Check_Embedded_Values;
private
Hidden_Object : Imp_H.Scalar_To_Normalize; -- not initialized
Hidden_Number : Imp_H.Small_Number; -- not initialized
end Thingy;
end CXH1001_0.CXH1001_1;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
with Report;
package body CXH1001_0.CXH1001_1 is
Childs_Object : Imp_H.Scalar_To_Normalize; -- not initialized
protected body Thingy is
procedure Check_Embedded_Values is
begin
if Imp_H.Default_For_Scalar_To_Normalize_Is_In_Range then
if Childs_Object /= Imp_H.Default_For_Scalar_To_Normalize then
Report.Failed("Implicit initial value for child object is not "
& "the predicted value");
end if;
elsif Childs_Object'Valid and then STN_2_Num( Childs_Object ) in 0 ..
Imp_H.Scalar_To_Normalize'Pos(Imp_H.Scalar_To_Normalize'Last) then
Report.Failed("Implicit initial value for child object is a "
& "value of the type");
end if;
if Imp_H.Default_For_Scalar_To_Normalize_Is_In_Range then
if Hidden_Object /= Imp_H.Default_For_Scalar_To_Normalize then
Report.Failed("Implicit initial value for protected package object "
& "is not the predicted value");
end if;
elsif Hidden_Object'Valid and then STN_2_Num( Hidden_Object ) in 0 ..
Imp_H.Scalar_To_Normalize'Pos(Imp_H.Scalar_To_Normalize'Last) then
Report.Failed("Implicit initial value for protected component "
& "is a value of the type");
end if;
if Imp_H.Default_For_Small_Number_Is_In_Range then
if Hidden_Number /= Imp_H.Default_For_Small_Number then
Report.Failed("Implicit initial value for protected number "
& "is not the predicted value");
end if;
elsif Hidden_Number'Valid and then Hidden_Number in
0 .. Imp_H.Small_Number(Report.Ident_Int(Small_Last)) then
Report.Failed("Implicit initial value for protected number "
& "is a value of the type");
end if;
end Check_Embedded_Values;
end Thingy;
end CXH1001_0.CXH1001_1;
------------------------------------------------------------------- CXH1001
with Impdef.Annex_H;
with Report;
with CXH1001_0.CXH1001_1;
procedure CXH1001 is
package Imp_H renames Impdef.Annex_H;
use type CXH1001_0.Num;
My_Object : Imp_H.Scalar_To_Normalize; -- not initialized
Value : CXH1001_0.Num := CXH1001_0.STN_2_Num ( My_Object );
-- My_Object is not initialized
Parameter_Value : Imp_H.Scalar_To_Normalize
:= Imp_H.Scalar_To_Normalize'Last;
type Structure is record -- not initialized
Std_Int : Integer;
Scalar : Imp_H.Scalar_To_Normalize;
Num : CXH1001_0.Num;
end record;
S : Structure; -- not initialized
procedure Bad_Code( Unassigned : out Imp_H.Scalar_To_Normalize ) is
-- returns uninitialized OUT parameter
begin
if Report.Ident_Int( 0 ) = 1 then
Report.Failed( "Nothing is something" );
Unassigned := Imp_H.Scalar_To_Normalize'First;
end if;
end Bad_Code;
procedure Check( V : CXH1001_0.Num; Message : String ) is
begin
if Imp_H.Default_For_Scalar_To_Normalize_Is_In_Range then
if V /= Imp_H.Scalar_To_Normalize'Pos(
Imp_H.Default_For_Scalar_To_Normalize) then
Report.Failed(Message & ": Implicit initial value for object "
& "is not the predicted value");
end if;
elsif V'Valid and then V in
0 .. Imp_H.Scalar_To_Normalize'Pos(Imp_H.Scalar_To_Normalize'Last) then
Report.Failed(Message & ": Implicit initial value for object "
& "is a value of the type");
end if;
end Check;
begin -- Main test procedure.
Report.Test ("CXH1001", "Check that the configuration pragma " &
"Normalize_Scalars causes uninitialized scalar " &
"objects to be set to a predictable value. " &
"Check that multiple compilation units are " &
"affected. Check for uninitialized scalar " &
"objects that are subcomponents of composite " &
"objects, unassigned out parameters, have been " &
"allocated without an initial value, and are " &
"stand alone." );
CXH1001_0.Package_Check;
if My_Object'Valid then
Value := CXH1001_0.STN_2_Num ( My_Object ); -- My_Object not initialized
end if;
-- otherwise, we just leave Value uninitialized
Check( Value, "main procedure variable" );
Bad_Code( Parameter_Value );
if Parameter_Value'Valid then
Check( CXH1001_0.STN_2_Num ( Parameter_Value ), "Out parameter return" );
end if;
if S.Scalar'Valid then
Check( CXH1001_0.STN_2_Num ( S.Scalar ), "Record component" );
end if;
CXH1001_0.CXH1001_1.Thingy.Check_Embedded_Values;
Report.Result;
end CXH1001;
|