aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gnat.dg/opt32.adb
blob: 93f31c2ca5294c9f6b8d74a9b56f8627fb1034b4 (plain)
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
-- { dg-do compile }
-- { dg-options "-O2" }

with Ada.Containers; use Ada.Containers;
with Ada.Containers.Vectors;

function Opt32 return Natural is

   package My_Vectors
      is new Vectors (Index_Type => Natural, Element_Type => Integer);
   use My_Vectors;

   V : Vector;

   function Sign_Changes return Natural is
      Cur      : Cursor := To_Cursor (V, 0);
      R        : Natural := 0;
      Negative : Boolean;
   begin
      Negative := Element (Cur) < 0;

      loop
         Cur := Next (Cur);
         exit when R > 100;

         if (Element (Cur) < 0) /= Negative then
            Negative := not Negative;
            R := R + 1;
         end if;
      end loop;

      return R;
   end;

begin
   return Sign_Changes;
end;