Debian Codegraph @

gcc/testsuite/gnat.dg/sso15.adb

raw
1 -- { dg-do run }
2 -- { dg-options "-gnatws" }
3
4 with System;
5 with Ada.Unchecked_Conversion;
6
7 procedure SSO15 is
8
9 type Arr is array (1 .. Integer'Size) of Boolean;
10 pragma Pack (Arr);
11 for Arr'Scalar_Storage_Order use System.High_Order_First;
12
13 function To_Float is new Ada.Unchecked_Conversion (Arr, Float);
14 function To_Int is new Ada.Unchecked_Conversion (Arr, Integer);
15
16 type R_Float is record
17 F : Float;
18 end record;
19 for R_Float'Bit_Order use System.High_Order_First;
20 for R_Float'Scalar_Storage_Order use System.High_Order_First;
21
22 type R_Int is record
23 I : Integer;
24 end record;
25 for R_Int'Bit_Order use System.High_Order_First;
26 for R_Int'Scalar_Storage_Order use System.High_Order_First;
27
28 A : Arr := (1 .. 2 => True, others => False);
29
30 F1 : Float;
31 F2 : R_Float;
32 for F2'Address use A'Address;
33 pragma Import (Ada, F2);
34
35 I1 : Integer;
36 I2 : R_Int;
37 for I2'Address use A'Address;
38 pragma Import (Ada, I2);
39
40 begin
41 -- Check that converting to FP yields a big-endian value.
42 F1 := To_Float (A);
43 if F2.F /= F1 then
44 raise Program_Error;
45 end if;
46
47 -- Check that converting to integer yields a big-endian value.
48 I1 := To_Int (A);
49 if I2.I /= I1 then
50 raise Program_Error;
51 end if;
52 end;