OSDN Git Service

* gnat.dg/lto[12456].adb: Add "target lto" marker.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gnat.dg / unchecked_convert1.adb
1 -- { dg-do run }
2 -- { dg-options "-gnatws" }
3
4 with Ada.Unchecked_Conversion;
5
6 procedure Unchecked_Convert1 is
7   type Byte is mod 2**8;
8
9   type Stream is array (Natural range <>) of Byte;
10
11   type Rec is record
12     I1, I2 : Integer;
13   end record;
14
15   function Do_Sum (R : Rec) return Integer is
16   begin
17     return R.I1 + R.I2;
18   end;
19
20   function Sum (S : Stream) return Integer is
21     subtype Chunk is Stream (1 .. Rec'Size / 8);
22     function To_Chunk is new Ada.Unchecked_Conversion (Chunk, Rec);
23   begin
24     return Do_Sum (To_Chunk (S(S'First ..  S'First + Rec'Size / 8 - 1)));
25   end;
26
27   A : Stream (1..9);
28   I : Integer;
29
30 begin
31   I := Sum (A(1..8));
32 end;