Commit Graph

161741 Commits

Author SHA1 Message Date
Bob Duff
2a5ec8e662 [Ada] Minor comment fix
2018-05-30  Bob Duff  <duff@adacore.com>

gcc/ada/

	* exp_ch7.adb: Minor comment fix.

From-SVN: r260926
2018-05-30 08:56:35 +00:00
Ed Schonberg
5d5148841e [Ada] Unnesting: properly handle subprogram instantiations
2018-05-30  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_unst.adb (Visit_Node): Handle properly subprogram instantiations
	that have no corresponding body and appear as attributes of the
	corresponding wrapper package declaration.
	(Register_Subprogram): New subprogram, used for subprogram bodies and
	for subprogram instantiations to enter callable entity into Subp table.

From-SVN: r260925
2018-05-30 08:56:29 +00:00
Hristian Kirtchev
1df65b8982 [Ada] Secondary stack implementation clean up
This patch reimplements the secondary stack runtime support as follows:

   * The compiler interface remains unchanged. This applies to both types and
     subprograms used by the compiler to create and manage secondary stacks.

   * The secondary stack is no longer a doubly linked list of chunks.

   * Various allocation scenarios are now handled by the same mechanism.

In addition, the patch introduces a lightweight private interface for testing
purposes.

------------
-- Source --
------------

--  comparator.ads

generic
   type Field_Typ is private;
   --  The type of the field being compared

   with function Image (Val : Field_Typ) return String;
   --  Field-to-String converted

procedure Comparator
  (Field_Nam    : String;
   Actual_Val   : Field_Typ;
   Expected_Val : Field_Typ);
--  Compare actual value Actual_Val against expected value Expected_Val for
--  field Field_Nam. Emit an error if this is not the case.

--  comparator.adb

with Ada.Text_IO; use Ada.Text_IO;

procedure Comparator
  (Field_Nam    : String;
   Actual_Val   : Field_Typ;
   Expected_Val : Field_Typ)
is
begin
   if Actual_Val /= Expected_Val then
      Put_Line (Field_Nam);
      Put_Line ("  Actual   :" & Image (Actual_Val));
      Put_Line ("  Expected :" & Image (Expected_Val));
   end if;
end Comparator;

--  debugger.ads

package Debugger is

   Verbouse : constant Boolean := False;
   --  Set to True in order to obtain verbouse output

   procedure Output (Msg : String);
   --  Emit Msg to standard output if Verbouse is True

end Debugger;

--  debugger.adb

with Ada.Text_IO; use Ada.Text_IO;

package body Debugger is

   ------------
   -- Output --
   ------------

   procedure Output (Msg : String) is
   begin
      if Verbouse then
         Put_Line (Msg);
      end if;
   end Output;
end Debugger;

--  s-sestte.ads

package System.Secondary_Stack.Tester is

   procedure Test_Dynamic_Stack_Dynamic_Chunks;
   --  Test various properties of a dynamic stack's dynamic chunks

   procedure Test_Dynamic_Stack_Illegal_Allocations;
   --  Test whether illegal allocations on a dynamic stack are properly
   --  detected and reported.

   procedure Test_Dynamic_Stack_Static_Chunk;
   --  Test various properties of a dynamic stack's static chunk

   procedure Test_Dynamic_Stack_Zero_Chunk_Size;
   --  Test various properties of a dynamic stack with default chunk size of
   --  zero.

   procedure Test_Static_Stack_Illegal_Allocations;
   --  Test whether illegal allocations on a static stack are properly
   --  detected and reported.

   procedure Test_Static_Stack_Overflow;
   --  Test whether overflow of a static stack's static chunk is properly
   --  detected and reported.

   procedure Test_Static_Stack_Static_Chunk;
   --  Test various properties of a static chunk's static chunk

end System.Secondary_Stack.Tester;

--  s-sestte.adb

with Ada.Assertions;          use Ada.Assertions;
with Ada.Text_IO;             use Ada.Text_IO;
with System;                  use System;
with System.Parameters;       use System.Parameters;
with System.Soft_Links;       use System.Soft_Links;
with System.Storage_Elements; use System.Storage_Elements;

with Comparator;
with Debugger;                use Debugger;

package body System.Secondary_Stack.Tester is

   Units : constant := Standard'Maximum_Alignment;
   --  Each allocation of the secondary stack is rouded up to the nearest
   --  multiple of the maximum alignment. This value is called a "unit" in
   --  order to facilitate further allocations.

   -----------------------
   -- Local subprograms --
   -----------------------

   procedure Compare_Boolean is
     new Comparator
           (Field_Typ => Boolean,
            Image     => Boolean'Image);

   procedure Compare_Chunk_Count is
     new Comparator
           (Field_Typ => Chunk_Count,
            Image     => Chunk_Count'Image);

   procedure Compare_Chunk_Id is
     new Comparator
           (Field_Typ => Chunk_Id,
            Image     => Chunk_Id'Image);

   procedure Compare_Memory_Index is
     new Comparator
           (Field_Typ => Memory_Index,
            Image     => Memory_Index'Image);

   procedure Compare_Memory_Size is
     new Comparator
           (Field_Typ => Memory_Size,
            Image     => Memory_Size'Image);

   procedure Compare_MSWI is
     new Comparator
           (Field_Typ => Memory_Size_With_Invalid,
            Image     => Memory_Size_With_Invalid'Image);

   procedure Initialize_Stack (Size : Memory_Size);
   --  Create a new secondary stack for the calling task where the default
   --  chunk size is Size.

   procedure Match_Chunk
     (Match_Nam : String;
      Actual    : Chunk_Info;
      Expected  : Chunk_Info);
   --  Check whether actual chunk info Actual matches expected chunk info
   --  Expected. Match_Nam is the name of the match.

   procedure Match_Pointer
     (Actual    : Stack_Pointer_Info;
      Expected  : Stack_Pointer_Info);
   --  Check whether actual pointer info Actual matches expected pointer info
   --  Expected.

   procedure Match_Stack
     (Match_Nam : String;
      Actual    : Stack_Info;
      Expected  : Stack_Info);
   --  Check whether actual stack info Stack matches expected stack info
   --  Expected. Match_Nam is the name of the match.

   procedure Test_Static_Chunk (Def_Chunk_Size : Memory_Size);
   --  Common testing for properties of the static chunk for both static and
   --  dynamic secondary stacks. Def_Chunk_Size denotes the default size of a
   --  secondary stack chunk. This routine assumes that the secondary stack
   --  can fit 12 * Units.

   ----------------------
   -- Initialize_Stack --
   ----------------------

   procedure Initialize_Stack (Size : Memory_Size) is
      Stack : SS_Stack_Ptr;

   begin
      --  Obtain the secondary stack of the calling task

      Stack := Get_Sec_Stack.all;

      --  If the calling task has an existing secodnary stack, destroy it
      --  because this scenario utilizes a custom secondary stack.

      if Stack /= null then

         --  Destroy the existing secondary stack because it will be replaced
         --  with a new one.

         SS_Free (Stack);
         pragma Assert (Stack = null);
      end if;

      --  Create a brand new empty secondary stack

      SS_Init (Stack, Size);
      pragma Assert (Stack /= null);

      --  Associate the secondary stack with the calling task

      Set_Sec_Stack (Stack);
   end Initialize_Stack;

   -----------------
   -- Match_Chunk --
   -----------------

   procedure Match_Chunk
     (Match_Nam : String;
      Actual    : Chunk_Info;
      Expected  : Chunk_Info)
   is
   begin
      Output (Match_Nam);

      Compare_MSWI
        ("Size",               Actual.Size,
                               Expected.Size);
      Compare_MSWI
        ("Size_Up_To_Chunk",   Actual.Size_Up_To_Chunk,
                               Expected.Size_Up_To_Chunk);
   end Match_Chunk;

   -------------------
   -- Match_Pointer --
   -------------------

   procedure Match_Pointer
     (Actual    : Stack_Pointer_Info;
      Expected  : Stack_Pointer_Info)
   is
   begin
      Compare_Memory_Index
        ("Byte",               Actual.Byte,
                               Expected.Byte);
      Compare_Chunk_Id
        ("Chunk",              Actual.Chunk,
                               Expected.Chunk);
   end Match_Pointer;

   -----------------
   -- Match_Stack --
   -----------------

   procedure Match_Stack
     (Match_Nam : String;
      Actual    : Stack_Info;
      Expected  : Stack_Info)
   is
   begin
      Output (Match_Nam);

      Compare_Memory_Size
        ("Default_Chunk_Size", Actual.Default_Chunk_Size,
                               Expected.Default_Chunk_Size);
      Compare_Boolean
        ("Freeable",           Actual.Freeable,
                               Expected.Freeable);
      Compare_Memory_Size
        ("High_Water_Mark",    Actual.High_Water_Mark,
                               Expected.High_Water_Mark);
      Compare_Chunk_Count
        ("Number_Of_Chunks",   Actual.Number_Of_Chunks,
                               Expected.Number_Of_Chunks);

      Match_Pointer (Actual.Top, Expected.Top);
   end Match_Stack;

   ---------------------------------------
   -- Test_Dynamic_Stack_Dynamic_Chunks --
   ---------------------------------------

   procedure Test_Dynamic_Stack_Dynamic_Chunks is
      Def_Chunk_Size : constant Memory_Size := 4 * Units;

      Dummy_1 : Address;
      Dummy_2 : Address;
      Dummy_3 : Address;
      Dummy_4 : Address;
      Mark    : Mark_Id;

   begin
      Output ("#### Test_DSDCs ####");

      --  Create a brand new empty secondary stack
      --
      --       1  2  3  4
      --    +------------+
      --    |            |
      --    +------------+

      Initialize_Stack (Def_Chunk_Size);

      Match_Stack
        (Match_Nam => "Empty stack",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 0,
            Number_Of_Chunks   => 1,
            Top                => (Byte => 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "Empty stack, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      --       Mark
      --       |
      --       1  2  3  4
      --    +------------+
      --    |            |
      --    +------------+

      Mark := SS_Mark;

      --       Mark                           Top.Byte
      --       |                              |
      --       1  2  3  4      1  2  3  4  5  6
      --    +------------+  +---------------+
      --    |            |->|###############|
      --    +------------+  +---------------+
      --       1  2  3  4      5  6  7  8  9
      --                                   |
      --                                   HWM

      SS_Allocate (Dummy_1, 5 * Units);

      Match_Stack
        (Match_Nam => "After 5u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 9 * Units,
            Number_Of_Chunks   => 2,
            Top                => (Byte => (5 * Units) + 1, Chunk => 2)));

      Match_Chunk
        (Match_Nam => "After 5u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      Match_Chunk
        (Match_Nam => "After 5u allocation, chunk 2",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 2),
         Expected  =>
           (Size             => 5 * Units,
            Size_Up_To_Chunk => 4 * Units));

      --       Mark                                     Top.Byte
      --       |                                        |
      --       1  2  3  4      1  2  3  4  5      1  2  3  4
      --    +------------+  +---------------+  +------------+
      --    |            |->|###############|->|######      |
      --    +------------+  +---------------+  +------------+
      --       1  2  3  4      5  6  7  8  9     10 11 12 13
      --                                             |
      --                                             HWM
      --
      --  Note that the size of Chunk 3 defaults to 4 because the request is
      --  smaller than the default chunk size.

      SS_Allocate (Dummy_2, 2 * Units);

      Match_Stack
        (Match_Nam => "After 2u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 11 * Units,
            Number_Of_Chunks   => 3,
            Top                => (Byte => (2 * Units) + 1, Chunk => 3)));

      Match_Chunk
        (Match_Nam => "After 2u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      Match_Chunk
        (Match_Nam => "After 2u allocation, chunk 2",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 2),
         Expected  =>
           (Size             => 5 * Units,
            Size_Up_To_Chunk => 4 * Units));

      Match_Chunk
        (Match_Nam => "After 2u allocation, chunk 3",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 3),
         Expected  =>
           (Size             => 4 * Units,
            Size_Up_To_Chunk => 9 * Units));

      --       Top.Byte
      --       |
      --       1  2  3  4         1  2  3  4  5         1  2  3  4
      --    +------------+     +---------------+     +------------+
      --    |            | --> |###############| --> |######      |
      --    +------------+     +---------------+     +------------+
      --       1  2  3  4         5  6  7  8  9        10 11 12 13
      --                                                   |
      --                                                   HWM

      SS_Release (Mark);

      --                Top.Byte
      --                |
      --       1  2  3  4         1  2  3  4  5         1  2  3  4
      --    +------------+     +---------------+     +------------+
      --    |#########   | --> |###############| --> |######      |
      --    +------------+     +---------------+     +------------+
      --       1  2  3  4         5  6  7  8  9         10 11 12 13
      --                                                   |
      --                                                   HWM

      SS_Allocate (Dummy_3, 3 * Units);

      Match_Stack
        (Match_Nam => "After 3u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 11 * Units,
            Number_Of_Chunks   => 3,
            Top                => (Byte => (3 * Units) + 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "After 3u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      Match_Chunk
        (Match_Nam => "After 3u allocation, chunk 2",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 2),
         Expected  =>
           (Size             => 5 * Units,
            Size_Up_To_Chunk => 4 * Units));

      Match_Chunk
        (Match_Nam => "After 3u allocation, chunk 3",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 3),
         Expected  =>
           (Size             => 4 * Units,
            Size_Up_To_Chunk => 9 * Units));

      --                                                  Top.Byte
      --                                                  |
      --       1  2  3  4         1  2  3  4  5  6  7  8  9
      --    +------------+     +------------------------+
      --    |#########   | --> |########################|
      --    +------------+     +------------------------+
      --       1  2  3  4         5  6  7  8  9 10 11 12
      --                                               |
      --                                               HWM

      SS_Allocate (Dummy_4, 8 * Units);

      Match_Stack
        (Match_Nam => "After 8u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 12 * Units,
            Number_Of_Chunks   => 2,
            Top                => (Byte => (8 * Units) + 1, Chunk => 2)));

      Match_Chunk
        (Match_Nam => "After 8u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      Match_Chunk
        (Match_Nam => "After 8u allocation, chunk 2",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 2),
         Expected  =>
           (Size             => 8 * Units,
            Size_Up_To_Chunk => 4 * Units));

   exception
      when others =>
         Put_Line ("Test_DSDCs: unexpected exception");
   end Test_Dynamic_Stack_Dynamic_Chunks;

   --------------------------------------------
   -- Test_Dynamic_Stack_Illegal_Allocations --
   --------------------------------------------

   procedure Test_Dynamic_Stack_Illegal_Allocations is
      Def_Chunk_Size : constant Memory_Size := 4 * Units;

      Dummy_1 : Address;
      Dummy_2 : Address;

   begin
      Output ("#### Test_DSIA ####");

      --  Create a brand new empty secondary stack
      --
      --       1  2  3  4
      --    +------------+
      --    |            |
      --    +------------+

      Initialize_Stack (Def_Chunk_Size);

      Match_Stack
        (Match_Nam => "Empty stack",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 0,
            Number_Of_Chunks   => 1,
            Top                => (Byte => 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "Empty stack, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      --  It should not be possible to allocate an object of size zero

      Zero_Allocation : begin
         SS_Allocate (Dummy_1, 0);
         Put_Line ("Test_DSIA: ERROR: zero allocation succeeded");

      exception
         when Assertion_Error =>
            Match_Stack
              (Match_Nam => "After zero allocation",
               Actual    => Get_Stack_Info (Get_Sec_Stack.all),
               Expected  =>
                 (Default_Chunk_Size => Def_Chunk_Size,
                  Freeable           => True,
                  High_Water_Mark    => 0,
                  Number_Of_Chunks   => 1,
                  Top                => (Byte => 1, Chunk => 1)));

            Match_Chunk
              (Match_Nam => "After zero allocation",
               Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
               Expected  =>
                 (Size             => Def_Chunk_Size,
                  Size_Up_To_Chunk => 0));

         when others =>
            Put_Line ("Test_DSIA: zero allocation: unexpected exception");
      end Zero_Allocation;

      --  It should not be possible to allocate an object of negative size

      Negative_Allocation : begin
         SS_Allocate (Dummy_2, -8);
         Put_Line ("Test_DSIA: ERROR: negative allocation succeeded");

      exception
         when Assertion_Error =>
            Match_Stack
              (Match_Nam => "After negative allocation",
               Actual    => Get_Stack_Info (Get_Sec_Stack.all),
               Expected  =>
                 (Default_Chunk_Size => Def_Chunk_Size,
                  Freeable           => True,
                  High_Water_Mark    => 0,
                  Number_Of_Chunks   => 1,
                  Top                => (Byte => 1, Chunk => 1)));

            Match_Chunk
              (Match_Nam => "After negative allocation",
               Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
               Expected  =>
                 (Size             => Def_Chunk_Size,
                  Size_Up_To_Chunk => 0));

         when others =>
            Put_Line ("Test_DSIA: negative allocation: unexpected exception");
      end Negative_Allocation;

   exception
      when others =>
         Put_Line ("Test_DSIA: unexpected exception");
   end Test_Dynamic_Stack_Illegal_Allocations;

   -------------------------------------
   -- Test_Dynamic_Stack_Static_Chunk --
   -------------------------------------

   procedure Test_Dynamic_Stack_Static_Chunk is
      Def_Chunk_Size : constant Memory_Size := 12 * Units;

      Dummy_1 : Address;
      Dummy_2 : Address;
      Dummy_3 : Address;
      Dummy_4 : Address;
      Mark_1  : Mark_Id;
      Mark_2  : Mark_Id;

   begin
      Output ("#### Test_DSSC ####");

      --  Create a brand new empty secondary stack
      --
      --       1  2  3  4  5  6  7  8  9 10 11 12
      --    +------------------------------------+
      --    |                                    |
      --    +------------------------------------+

      Initialize_Stack  (Def_Chunk_Size);
      Test_Static_Chunk (Def_Chunk_Size);

   exception
      when others =>
         Put_Line ("Test_DSSC: unexpected exception");
   end Test_Dynamic_Stack_Static_Chunk;

   ----------------------------------------
   -- Test_Dynamic_Stack_Zero_Chunk_Size --
   ----------------------------------------

   procedure Test_Dynamic_Stack_Zero_Chunk_Size is
      Def_Chunk_Size : constant Memory_Size := 0;

      Dummy_1 : Address;
      Dummy_2 : Address;
      Mark    : Mark_Id;

   begin
      Output ("#### Test_DSZCS ####");

      --  Create a brand new empty secondary stack
      --
      --    ++
      --    ||
      --    ++

      Initialize_Stack (Def_Chunk_Size);

      Match_Stack
        (Match_Nam => "Empty stack",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 0,
            Number_Of_Chunks   => 1,
            Top                => (Byte => 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "Empty stack, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      --       Mark
      --       |
      --       1
      --    ++
      --    ||
      --    ++

      Mark := SS_Mark;

      --       Mark         Top.Byte
      --       |            |
      --       |   1  2  3  4
      --    ++  +---------+
      --    ||->|#########|
      --    ++  +---------+
      --           1  2  3
      --                 |
      --                 HWM

      SS_Allocate (Dummy_1, 3 * Units);

      Match_Stack
        (Match_Nam => "After 3u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 3 * Units,
            Number_Of_Chunks   => 2,
            Top                => (Byte => (3 * Units) + 1, Chunk => 2)));

      Match_Chunk
        (Match_Nam => "After 3u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      Match_Chunk
        (Match_Nam => "After 3u allocation, chunk 2",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 2),
         Expected  =>
           (Size             => 3 * Units,
            Size_Up_To_Chunk => 0));

      --       Mark                   Top.Byte
      --       |                      |
      --       |   1  2  3      1  2  3
      --    ++  +---------+  +------+
      --    ||->|#########|->|######|
      --    ++  +---------+  +------+
      --           1  2  3      4  5
      --                           |
      --                           HWM

      SS_Allocate (Dummy_2, 2 * Units);

      Match_Stack
        (Match_Nam => "After 2u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 5 * Units,
            Number_Of_Chunks   => 3,
            Top                => (Byte => (2 * Units) + 1, Chunk => 3)));

      Match_Chunk
        (Match_Nam => "After 2u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      Match_Chunk
        (Match_Nam => "After 2u allocation, chunk 2",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 2),
         Expected  =>
           (Size             => 3 * Units,
            Size_Up_To_Chunk => 0));

      Match_Chunk
        (Match_Nam => "After 2u allocation, chunk 3",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 3),
         Expected  =>
           (Size             => 2 * Units,
            Size_Up_To_Chunk => 3 * Units));

      --       Top.Byte
      --       |
      --       |   1  2  3      1  2
      --    ++  +---------+  +------+
      --    ||->|#########|->|######|
      --    ++  +---------+  +------+
      --           1  2  3      4  5
      --                           |
      --                           HWM

      SS_Release (Mark);

      --                             Top.Byte
      --                             |
      --           1  2  3  4  5  6  7
      --    ++  +------------------+
      --    ||->|##################|
      --    ++  +------------------+
      --           1  2  3  4  5  6
      --                          |
      --                          HWM

      SS_Allocate (Dummy_2, 6 * Units);

      Match_Stack
        (Match_Nam => "After 6u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 6 * Units,
            Number_Of_Chunks   => 2,
            Top                => (Byte => (6 * Units) + 1, Chunk => 2)));

      Match_Chunk
        (Match_Nam => "After 6u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      Match_Chunk
        (Match_Nam => "After 6u allocation, chunk 2",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 2),
         Expected  =>
           (Size             => 6 * Units,
            Size_Up_To_Chunk => 0));

   exception
      when others =>
         Put_Line ("Test_DSZCS: unexpected exception");
   end Test_Dynamic_Stack_Zero_Chunk_Size;

   -----------------------
   -- Test_Static_Chunk --
   -----------------------

   procedure Test_Static_Chunk (Def_Chunk_Size : Memory_Size) is
      Dummy_1 : Address;
      Dummy_2 : Address;
      Dummy_3 : Address;
      Dummy_4 : Address;
      Mark_1  : Mark_Id;
      Mark_2  : Mark_Id;

   begin
      --  This routine assumes an empty secondary stack

      Match_Stack
        (Match_Nam => "Empty stack",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 0,
            Number_Of_Chunks   => 1,
            Top                => (Byte => 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "Empty stack, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      --                   Top.Byte
      --                   |
      --       1  2  3  4  5  6  7  8  9 10 11 12
      --    +------------------------------------. . .
      --    |############
      --    +------------------------------------. . .
      --                |
      --                HWM

      SS_Allocate (Dummy_1, 4 * Units);

      Match_Stack
        (Match_Nam => "After 4u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 4 * Units,
            Number_Of_Chunks   => 1,
            Top                => (Byte => (4 * Units) + 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "After 4u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      --                   Mark_1
      --                   Top.Byte
      --                   |
      --       1  2  3  4  5  6  7  8  9 10 11 12
      --    +------------------------------------. . .
      --    |############
      --    +------------------------------------. . .
      --                |
      --                HWM

      Mark_1 := SS_Mark;

      --                   Mark_1
      --                   |              Top.Byte
      --                   |              |
      --       1  2  3  4  5  6  7  8  9 10 11 12
      --    +------------------------------------. . .
      --    |###########################
      --    +------------------------------------. . .
      --                               |
      --                               HWM

      SS_Allocate (Dummy_2, 5 * Units);

      Match_Stack
        (Match_Nam => "After 5u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 9 * Units,
            Number_Of_Chunks   => 1,
            Top                => (Byte => (9 * Units) + 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "After 5u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      --                   Mark_1         Mark_2
      --                   |              Top.Byte
      --                   |              |
      --       1  2  3  4  5  6  7  8  9 10 11 12
      --    +------------------------------------. . .
      --    |###########################
      --    +------------------------------------. . .
      --                               |
      --                               HWM

      Mark_2 := SS_Mark;

      --                   Mark_1         Mark_2
      --                   |              |     Top.Byte
      --                   |              |     |
      --       1  2  3  4  5  6  7  8  9 10 11 12
      --    +------------------------------------. . .
      --    |#################################
      --    +------------------------------------. . .
      --                                     |
      --                                     HWM

      SS_Allocate (Dummy_3, 2 * Units);

      Match_Stack
        (Match_Nam => "After 2u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 11 * Units,
            Number_Of_Chunks   => 1,
            Top                => (Byte => (11 * Units) + 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "After 2u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      --                   Mark_1
      --                   |              Top.Byte
      --                   |              |
      --       1  2  3  4  5  6  7  8  9 10 11 12
      --    +------------------------------------. . .
      --    |#################################
      --    +------------------------------------. . .
      --                                     |
      --                                     HWM

      SS_Release (Mark_2);

      Match_Stack
        (Match_Nam => "After Mark_2 release",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 11 * Units,
            Number_Of_Chunks   => 1,
            Top                => (Byte => (9 * Units) + 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "After Mark_2 release, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      --                   Top.Byte
      --                   |
      --       1  2  3  4  5  6  7  8  9 10 11 12
      --    +------------------------------------. . .
      --    |#################################
      --    +------------------------------------. . .
      --                                     |
      --                                     HWM

      SS_Release (Mark_1);

      Match_Stack
        (Match_Nam => "After Mark_1 release",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 11 * Units,
            Number_Of_Chunks   => 1,
            Top                => (Byte => (4 * Units) + 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "After Mark_1 release, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));

      --                                        Top.Byte
      --                                        |
      --       1  2  3  4  5  6  7  8  9 10 11 12
      --    +------------------------------------. . .
      --    |#################################
      --    +------------------------------------. . .
      --                                     |
      --                                     HWM

      SS_Allocate (Dummy_4, 6 * Units);

      Match_Stack
        (Match_Nam => "After 6u allocation",
         Actual    => Get_Stack_Info (Get_Sec_Stack.all),
         Expected  =>
           (Default_Chunk_Size => Def_Chunk_Size,
            Freeable           => True,
            High_Water_Mark    => 11 * Units,
            Number_Of_Chunks   => 1,
            Top                => (Byte => (10 * Units) + 1, Chunk => 1)));

      Match_Chunk
        (Match_Nam => "After 6u allocation, chunk 1",
         Actual    => Get_Chunk_Info (Get_Sec_Stack.all, 1),
         Expected  =>
           (Size             => Def_Chunk_Size,
            Size_Up_To_Chunk => 0));
   end Test_Static_Chunk;

   -------------------------------------------
   -- Test_Static_Stack_Illegal_Allocations --
   -------------------------------------------

   procedure Test_Static_Stack_Illegal_Allocations is
      Dummy_1 : Address;
      Dummy_2 : Address;

   begin
      Output ("#### Test_SSIA ####");

      --  It should not be possible to allocate an object of size zero

      Zero_Allocation : begin
         SS_Allocate (Dummy_1, 0);
         Put_Line ("Test_SSIA: ERROR: zero allocation succeeded");

      exception
         when Assertion_Error =>
            Output ("After zero allocation");

         when others =>
            Put_Line ("Test_SSIA: zero allocation: unexpected exception");
      end Zero_Allocation;

      --  It should not be possible to allocate an object of negative size

      Negative_Allocation : begin
         SS_Allocate (Dummy_2, -8);
         Put_Line ("Test_SSIA: ERROR: negative allocation succeeded");

      exception
         when Assertion_Error =>
            Output ("After negative allocation");

         when others =>
            Put_Line ("Test_SSIA: negative allocation: unexpected exception");
      end Negative_Allocation;

   exception
      when others =>
         Put_Line ("Test_SSIA: unexpected exception");
   end Test_Static_Stack_Illegal_Allocations;

   --------------------------------
   -- Test_Static_Stack_Overflow --
   --------------------------------

   procedure Test_Static_Stack_Overflow is
      Info  : constant Stack_Info := Get_Stack_Info (Get_Sec_Stack.all);
      Dummy : Address;

   begin
      Output ("#### Test_SSO ####");

      --  Try to overflow the static chunk

      Overflow : begin
         SS_Allocate (Dummy, Storage_Offset (Info.Default_Chunk_Size));
         Put_Line ("Test_SSO: ERROR: Overflow not detected");

      exception
         when Storage_Error =>
            Output ("After overflow");

         when others =>
            Put_Line ("Test_SSO: overflow: unexpected exception");
      end Overflow;

   exception
      when others =>
         Put_Line ("Test_SSO: unexpected exception");
   end Test_Static_Stack_Overflow;

   ------------------------------------
   -- Test_Static_Stack_Static_Chunk --
   ------------------------------------

   procedure Test_Static_Stack_Static_Chunk is
      Info : Stack_Info;

   begin
      Output ("#### Test_SSSC ####");

      Info := Get_Stack_Info (Get_Sec_Stack.all);
      Test_Static_Chunk (Info.Default_Chunk_Size);

   exception
      when others =>
         Put_Line ("Test_SSSC: unexpected exception");
   end Test_Static_Stack_Static_Chunk;

end System.Secondary_Stack.Tester;

--  main.adb

with Ada.Text_IO;                   use Ada.Text_IO;
with System.Parameters;             use System.Parameters;
with System.Secondary_Stack.Tester; use System.Secondary_Stack.Tester;

procedure Main is
   task Tester;

   --  The various scenarios are tested within a task because this guarantees
   --  that on a normal compilation, the task's secondary stack is created on
   --  the heap and can be safely freed and replaced with a custom one.

   task body Tester is
   begin
      if Sec_Stack_Dynamic then
         Test_Dynamic_Stack_Static_Chunk;
         Test_Dynamic_Stack_Dynamic_Chunks;
         Test_Dynamic_Stack_Zero_Chunk_Size;
         Test_Dynamic_Stack_Illegal_Allocations;
      else
         Test_Static_Stack_Static_Chunk;
         Test_Static_Stack_Overflow;
         Test_Static_Stack_Illegal_Allocations;
      end if;
   end Tester;

begin null; end Main;

-----------------
-- Compilation --
-----------------

$ gnatmake -a -f -q -gnata -gnatws main.adb
$ ./main

2018-05-30  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* libgnat/s-secsta.adb: Reimplement the secondary stack support.
	* libgnat/s-secsta.ads: Update the documentation of all routines in the
	public part of the package.  Reimplement the private part of the
	package to account for the new secondary stack structure.  Add types
	and subprograms for testing purposes.  Add several documentation
	sections.

From-SVN: r260924
2018-05-30 08:56:23 +00:00
Hristian Kirtchev
f537fc00c7 [Ada] Minor reformatting
2018-05-30  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* exp_aggr.adb, exp_ch3.adb, exp_ch4.adb, exp_ch7.adb, exp_unst.adb,
	exp_util.adb, exp_util.ads, libgnat/a-calcon.adb, libgnat/a-calcon.ads,
	libgnat/s-os_lib.adb, repinfo.adb, sem_ch3.adb, sem_disp.adb,
	sem_disp.ads, sem_util.adb: Minor reformatting.

From-SVN: r260923
2018-05-30 08:56:18 +00:00
Arnaud Charlet
c0368be1a1 [Ada] Move special flags for Ada runtime files from Makefile.in to Makefile.rtl
2018-05-30  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* gcc-interface/Makefile.in: Move special flags for Ada runtime files
	from here...
	* Makefile.rtl: ... to here.  Update comments.  Protect call to
	"GCC_FOR_TARGET" in case target_os isn't defined.

From-SVN: r260922
2018-05-30 08:56:12 +00:00
Arnaud Charlet
c667752e4c [Ada] Move target pair settings in Makefiles
2018-05-30  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* gcc-interface/Makefile.in: Move target pair settings from here...
	* Makefile.rtl: ... to here.
	(setup-rts): New target.

From-SVN: r260921
2018-05-30 08:56:05 +00:00
Jonathan Wakely
b005486b25 Replace dead store with early return
* typeck.c (cxx_sizeof_or_alignof_type): Return size_one_node instead
	of using it in dead store.

From-SVN: r260920
2018-05-30 09:18:33 +01:00
Richard Sandiford
6e246559b8 Use poly_int tree accessors
This patch generalises various places that used hwi tree accessors so
that they can handle poly_ints instead.  In many cases these changes
are by inspection rather than because something had shown them to be
necessary.

I think the alias.c part is a minor bug fix: previously we used
fits_uhwi_p for a signed HOST_WIDE_INT (which the caller does
treat as signed rather than unsigned).  We also checked whether
each individual offset overflowed but didn't check whether the
sum did.

2018-05-30  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	* alias.c (adjust_offset_for_component_ref): Use poly_int_tree_p
	and wi::to_poly_offset.  Add the current offset and then check
	whether the sum fits, rather than using an unchecked addition of
	a checked term.  Check for a shwi rather than a uhwi.
	* expr.c (get_bit_range): Use tree_to_poly_uint64.
	(store_constructor): Use poly_int_tree_p.
	(expand_expr_real_1): Likewise.
	* function.c (assign_temp): Likewise.
	* fold-const.c (const_binop): Use poly_int_tree_p and
	wi::to_poly_offset.
	(fold_indirect_ref_1): Likewise.  Use multiple_p to attempt an exact
	division.
	* ipa-icf-gimple.c (func_checker::compare_operand): Use
	to_poly_offset for MEM offsets.
	* ipa-icf.c (sem_variable::equals): Likewise.
	* stor-layout.c (compute_record_mode): Use poly_int_tree_p.
	* tree-ssa-sccvn.c (ao_ref_init_from_vn_reference): Use
	wi::to_poly_offset for BIT_FIELD_REF offsets.
	(vn_reference_maybe_forwprop_address): Use poly_int_tree_p and
	wi::to_poly_offset.
	* var-tracking.c (emit_note_insn_var_location): Use
	tree_to_poly_uint64.

From-SVN: r260914
2018-05-30 06:31:47 +00:00
Ian Lance Taylor
bb3976df48 cmd/go, cmd/vet: make vet work with gccgo
Backport https://golang.org/cl/113715 and https://golang.org/cl/113716:
    
    cmd/go: don't pass -compiler flag to vet
    
    Without this running go vet -compiler=gccgo causes vet to fail.
    The vet tool does need to know the compiler, but it is passed in
    vetConfig.Compiler.
    
    cmd/go, cmd/vet, go/internal/gccgoimport: make vet work with gccgo
    
    When using gccgo/GoLLVM, there is no package file for a standard
    library package. Since it is impossible for the go tool to rebuild the
    package, and since the package file exists only in the form of a .gox
    file, this seems like the best choice. Unfortunately it was confusing
    vet, which wanted to see a real file. This caused vet to report errors
    about missing package files for standard library packages. The
    gccgoimporter knows how to correctly handle this case. Fix this by
    
    1) telling vet which packages are standard;
    2) letting vet skip those packages;
    3) letting the gccgoimporter handle this case.
    
    As a separate required fix, gccgo/GoLLVM has no runtime/cgo package,
    so don't try to depend on it (as it happens, this fixes golang/go#25324).
    
    The result is that the cmd/go vet tests pass when using -compiler=gccgo.
    
    Reviewed-on: https://go-review.googlesource.com/114516

From-SVN: r260913
2018-05-30 00:16:58 +00:00
GCC Administrator
fc27db2b42 Daily bump.
From-SVN: r260912
2018-05-30 00:16:38 +00:00
Ian Lance Taylor
4ec2cf3bd0 crypto/x509: specify path to AIX certificate file
Reviewed-on: https://go-review.googlesource.com/113179

From-SVN: r260908
2018-05-30 00:16:02 +00:00
Jim Wilson
5af3ff2159 RISC-V: Fix a comment typo.
* config/riscv/riscv.c (riscv_interrupt_type): Fix comment typo.

From-SVN: r260907
2018-05-29 15:31:17 -07:00
Jason Merrill
04eb9c5574 PR c++/67445 - returning temporary initializer_list.
PR c++/67711 - assigning from temporary initializer_list.
	PR c++/48562 - new initializer_list.
	* typeck.c (maybe_warn_about_returning_address_of_local): Also warn
	about returning local initializer_list.
	* cp-tree.h (AUTO_TEMP_NAME, TEMP_NAME_P): Remove.
	* call.c (build_over_call): Warn about assignment from temporary
	init_list.
	* init.c (build_new_1): Warn about 'new std::initializer_list'.
	(find_list_begin, maybe_warn_list_ctor): New.
	(perform_member_init): Use maybe_warn_list_ctor.

From-SVN: r260905
2018-05-29 16:04:52 -04:00
Uros Bizjak
5d2e68ea0a re PR target/85950 (Unsafe-math-optimizations regresses optimization using SSE4.1 roundss)
PR target/85950
	* config/i386/i386.md (l<rounding_insn><MODEF:mode><SWI48:mode>2):
	Enable for TARGET_SSE4_1 and generate rounds{s,d} and cvtts{s,d}2si{,q}
	sequence.
	(sse4_1_round<mode>2): Use nonimmediate_operand
	for operand 1 predicate.

testsuite/ChangeLog:

	PR target/85950
	* gcc.target/i386/pr85950.c: New test.

From-SVN: r260903
2018-05-29 20:35:34 +02:00
Martin Sebor
72930d9f29 PR middle-end/85888 - New test case c-c++-common/attr-nonstring-6.c from r260541 fails with excess errors
2018-05-29  Martin Sebor  <msebor@redhat.com>
	    Richard Biener  <rguenther@suse.de>

	PR testsuite/85888
	* calls.c (get_size_range): Call determine_value_range instead
	of get_value_range..
	* tree-vrp.h (determine_value_range): Declared new function.
	* tree-vrp.c (determine_value_range_1, determine_value_range): New.

Co-Authored-By: Richard Biener <rguenther@suse.de>

From-SVN: r260902
2018-05-29 12:29:04 -06:00
Marek Polacek
009bb506b1 re PR c++/85883 (class template argument deduction fails in new-expression)
PR c++/85883
	* init.c (build_new): Handle deducing a class with new
	with more than one argument.

	* g++.dg/cpp1z/class-deduction55.C: New test.
	* g++.dg/cpp1z/class-deduction56.C: New test.
	* g++.dg/cpp1z/class-deduction57.C: New test.

From-SVN: r260901
2018-05-29 17:44:07 +00:00
Jonathan Wakely
5baa6f8ebd Qualify another call in <variant>
* include/std/variant (__erased_dtor): Qualify call to __get.

From-SVN: r260900
2018-05-29 18:21:31 +01:00
Jakub Jelinek
69ce0c8c77 re PR c++/85952 (Bogus -Wunused-but-set-variable warning with array structured binding)
PR c++/85952
	* init.c (build_aggr_init): For structured binding initialized from
	array call mark_rvalue_use on the initializer.

	* g++.dg/warn/Wunused-var-33.C: New test.

From-SVN: r260899
2018-05-29 19:07:57 +02:00
Richard Biener
fec0bf3084 tree-vect-data-refs.c (vect_preserves_scalar_order_p): Make sure to use non-pattern stmts for get_earlier_stmt arguments.
2018-05-29  Richard Biener  <rguenther@suse.de>

	* tree-vect-data-refs.c (vect_preserves_scalar_order_p): Make
	sure to use non-pattern stmts for get_earlier_stmt arguments.
	* tree-vectorizer.h (get_earlier_stmt): Assert we do not get
	called on pattern stmts.
	(get_later_stmt): Likewise.

From-SVN: r260896
2018-05-29 14:35:28 +00:00
Martin Liska
0e8f29daae libgcov: report about a different timestamp (PR gcov-profile/85759).
2018-05-29  Martin Liska  <mliska@suse.cz>

        PR gcov-profile/85759
	* doc/gcov.texi: Document GCOV_ERROR_FILE and GCOV_EXIT_AT_ERROR
	env variables.
2018-05-29  Martin Liska  <mliska@suse.cz>

        PR gcov-profile/85759
	* libgcov-driver-system.c (gcov_error): Introduce usage of
        GCOV_EXIT_AT_ERROR env. variable.
	* libgcov-driver.c (merge_one_data): Print error that we
        overwrite a gcov file with a different timestamp.

From-SVN: r260895
2018-05-29 12:11:21 +00:00
Jakub Jelinek
e379122d1f tree-cfg.c (verify_gimple_assign_unary): Add checking for VEC_UNPACK_*_EXPR.
* tree-cfg.c (verify_gimple_assign_unary): Add checking for
	VEC_UNPACK_*_EXPR.
	(verify_gimple_assign_binary): Check TYPE_VECTOR_SUBPARTS for
	VEC_PACK_*_EXPR.

From-SVN: r260894
2018-05-29 14:01:26 +02:00
Jakub Jelinek
1bda738bab re PR target/85918 (Conversions to/from [unsigned] long long are not vectorized for AVX512DQ target)
PR target/85918
	* tree.def (VEC_UNPACK_FIX_TRUNC_HI_EXPR, VEC_UNPACK_FIX_TRUNC_LO_EXPR,
	VEC_PACK_FLOAT_EXPR): New tree codes.
	* tree-pretty-print.c (op_code_prio): Handle
	VEC_UNPACK_FIX_TRUNC_HI_EXPR and VEC_UNPACK_FIX_TRUNC_LO_EXPR.
	(dump_generic_node): Handle VEC_UNPACK_FIX_TRUNC_HI_EXPR,
	VEC_UNPACK_FIX_TRUNC_LO_EXPR and VEC_PACK_FLOAT_EXPR.
	* tree-inline.c (estimate_operator_cost): Likewise.
	* gimple-pretty-print.c (dump_binary_rhs): Handle VEC_PACK_FLOAT_EXPR.
	* fold-const.c (const_binop): Likewise.
	(const_unop): Handle VEC_UNPACK_FIX_TRUNC_HI_EXPR and
	VEC_UNPACK_FIX_TRUNC_LO_EXPR.
	* tree-cfg.c (verify_gimple_assign_unary): Likewise.
	(verify_gimple_assign_binary): Handle VEC_PACK_FLOAT_EXPR.
	* cfgexpand.c (expand_debug_expr): Handle VEC_UNPACK_FIX_TRUNC_HI_EXPR,
	VEC_UNPACK_FIX_TRUNC_LO_EXPR and VEC_PACK_FLOAT_EXPR.
	* expr.c (expand_expr_real_2): Likewise.
	* optabs.def (vec_packs_float_optab, vec_packu_float_optab,
	vec_unpack_sfix_trunc_hi_optab, vec_unpack_sfix_trunc_lo_optab,
	vec_unpack_ufix_trunc_hi_optab, vec_unpack_ufix_trunc_lo_optab): New
	optabs.
	* optabs.c (expand_widen_pattern_expr): For
	VEC_UNPACK_FIX_TRUNC_HI_EXPR and VEC_UNPACK_FIX_TRUNC_LO_EXPR use
	sign from result type rather than operand's type.
	(expand_binop_directly): For vec_packu_float_optab and
	vec_packs_float_optab allow result type to be different from operand's
	type.
	* optabs-tree.c (optab_for_tree_code): Handle
	VEC_UNPACK_FIX_TRUNC_HI_EXPR, VEC_UNPACK_FIX_TRUNC_LO_EXPR and
	VEC_PACK_FLOAT_EXPR.  Formatting fixes.
	* tree-vect-generic.c (expand_vector_operations_1):  Handle
	VEC_UNPACK_FIX_TRUNC_HI_EXPR, VEC_UNPACK_FIX_TRUNC_LO_EXPR and
	VEC_PACK_FLOAT_EXPR.
	* tree-vect-stmts.c (supportable_widening_operation): Handle
	FIX_TRUNC_EXPR.
	(supportable_narrowing_operation): Handle FLOAT_EXPR.
	* config/i386/i386.md (fixprefix, floatprefix): New code attributes.
	* config/i386/sse.md (*float<floatunssuffix>v2div2sf2): Rename to ...
	(float<floatunssuffix>v2div2sf2): ... this.  Formatting fix.
	(vpckfloat_concat_mode, vpckfloat_temp_mode, vpckfloat_op_mode): New
	mode attributes.
	(vec_pack<floatprefix>_float_<mode>): New expander.
	(vunpckfixt_mode, vunpckfixt_model, vunpckfixt_extract_mode): New mode
	attributes.
	(vec_unpack_<fixprefix>fix_trunc_lo_<mode>,
	vec_unpack_<fixprefix>fix_trunc_hi_<mode>): New expanders.
	* doc/md.texi (vec_packs_float_@var{m}, vec_packu_float_@var{m},
	vec_unpack_sfix_trunc_hi_@var{m}, vec_unpack_sfix_trunc_lo_@var{m},
	vec_unpack_ufix_trunc_hi_@var{m}, vec_unpack_ufix_trunc_lo_@var{m}):
	Document.
	* doc/generic.texi (VEC_UNPACK_FLOAT_HI_EXPR,
	VEC_UNPACK_FLOAT_LO_EXPR): Fix pasto in description.
	(VEC_UNPACK_FIX_TRUNC_HI_EXPR, VEC_UNPACK_FIX_TRUNC_LO_EXPR,
	VEC_PACK_FLOAT_EXPR): Document.

	* gcc.target/i386/avx512dq-pr85918.c: Add -mprefer-vector-width=512
	and -fno-vect-cost-model options.  Add aligned(64) attribute to the
	arrays.  Add suffix 1 to all functions and use 4 iterations rather
	than N.  Add functions with conversions to and from float.
	Add new set of functions with 8 iterations and another one
	with 16 iterations, expect 24 vectorized loops instead of just 4.
	* gcc.target/i386/avx512dq-pr85918-2.c: New test.

From-SVN: r260893
2018-05-29 13:58:24 +02:00
Richard Biener
f8c0baaf31 tree-vectorizer.h (struct vec_info): Add stmt_vec_infos member.
2018-05-29  Richard Biener  <rguenther@suse.de>

	* tree-vectorizer.h (struct vec_info): Add stmt_vec_infos
	member.
	(stmt_vec_info_vec): Make pointer.
	(init_stmt_vec_info_vec): Remove.
	(free_stmt_vec_info_vec): Likewise.
	(set_stmt_vec_info_vec): New function.
	(free_stmt_vec_infos): Likewise.
	(vinfo_for_stmt): Adjust for stmt_vec_info_vec indirection.
	(set_vinfo_for_stmt): Likewise.
	(get_earlier_stmt): Likewise.
	(get_later_stmt): Likewise.
	* tree-vectorizer.c (stmt_vec_info_vec): Make pointer.
	(vec_info::vec_info): Allocate stmt_vec_infos and set the global.
	(vec_info::~vec_info): Free stmt_vec_infos.
	(vectorize_loops): Set the global stmt_vec_info_vec to NULL.
	Remove old init_stmt_vec_info_vec/free_stmt_vec_info_vec calls.
	(pass_slp_vectorize::execute): Likewise.
	* tree-vect-stmts.c (init_stmt_vec_info_vec): Remove.
	(free_stmt_vec_info_vec): Likewise.
	(set_stmt_vec_info_vec): New function.
	(free_stmt_vec_infos): Likewise.
	* tree-vect-loop.c (_loop_vec_info::~_loop_vec_info): Set
	the global stmt_vec_info_vec.
	* tree-parloops.c (gather_scalar_reductions): Use
	set_stmt_vec_info_vec/free_stmt_vec_infos and maintain a local
	vector.

From-SVN: r260892
2018-05-29 11:49:44 +00:00
Richard Biener
092cb01cbf dominance.c (iterate_fix_dominators): Push/pop TV_DOMINANCE.
2018-05-29  Richard Biener  <rguenther@suse.de>

	* dominance.c (iterate_fix_dominators): Push/pop TV_DOMINANCE.

From-SVN: r260891
2018-05-29 11:44:16 +00:00
Martin Liska
c04f64807e Add vec::reverse.
2018-05-29  Martin Liska  <mliska@suse.cz>
	    David Malcolm  <dmalcolm@redhat.com>

	* vec.c (test_reverse): New.
	(vec_c_tests): Add new test.
	* vec.h (vl_ptr>::reverse): New function.

Co-Authored-By: David Malcolm <dmalcolm@redhat.com>

From-SVN: r260890
2018-05-29 09:55:02 +00:00
Eric Botcazou
86e74d5869 [Ada] Adjust documentation of -gnatn switch
This changes the wording in the documentation of the -gnatn switch to make
it use "units" rather than "modules" and also adjusts the usage message.

No functional changes.

2018-05-29  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* doc/gnat_ugn/building_executable_programs_with_gnat.rst (Alphabetical
	List of All Switches): Replace "modules" with "units".
	(Subprogram Inlining Control): Likewise.
	* gnat_ugn.texi: Regenerate.
	* usage.adb (Usage): Fix description of -gnatn switch.

From-SVN: r260889
2018-05-29 09:42:50 +00:00
Arnaud Charlet
4f95a81816 [Ada] Fix typos in Makefile.in
2018-05-29  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* gcc-interface/Makefile.in: Fix typos.

From-SVN: r260888
2018-05-29 09:42:45 +00:00
Ed Schonberg
795d00637d [Ada] Attach reference to finalizers to tree
2018-05-29  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_ch7.adb (Build_Finalizer_Call): Attach to tree the reference to
	the finalizer procedure in the At_End handler, for use in LLVM
	generation.

From-SVN: r260887
2018-05-29 09:42:39 +00:00
Javier Miranda
656412552b [Ada] Wrong equality on untagged private type
When a private type declaration T1 is completed with a derivation of an
untagged private type that overrides the predefined equality primitive, and the
full view of T2 is a derivation of another private type T2 whose full view is a
tagged type, the compiler may generate code that references the wrong equality
primitive when processing comparisons of objects of type T1.

2018-05-29  Javier Miranda  <miranda@adacore.com>

gcc/ada/

	* exp_ch4.adb (Expand_N_Op_Eq, Expand_Composite_Equality): Use the new
	subprogram Inherits_From_Tagged_Full_View to identify more reliably
	untagged private types completed with a derivation of an untagged
	private whose full view is a tagged type.
	* sem_util.ads, sem_util.adb (Inherits_From_Tagged_Full_View): New
	subprogram.
	(Collect_Primitive_Operations): Handle untagged private types completed
	with a derivation of an untagged private type whose full view is a
	tagged type. In such case, collecting the list of primitives we may
	find two equality primitives: one associated with the untagged private
	and another associated with the ultimate tagged type (and we must
	remove from the returned list this latter one).

gcc/testsuite/

	* gnat.dg/equal2.adb: New testcase.

From-SVN: r260886
2018-05-29 09:42:34 +00:00
Ed Schonberg
999acab61b [Ada] Unnesting: handle statement sequences that include an At_End handler
2018-05-29  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_unst.adb (Visit_Node): Handle statement sequences that include an
	At_End handler.

From-SVN: r260885
2018-05-29 09:42:29 +00:00
Eric Botcazou
944e24a31a [Ada] Plug small hole in -gnatR output
The -gnatR switch outputs representation information for locally-defined
types but it was skipping those defined in blocks without label, unlike
those defined in named blocks.  This change plugs this small hole.

The following procedure:

procedure P is
begin
  declare
    type R is record
      I : Integer;
    end record;
  begin
    null;
  end;
end;

must now generate the following output with -gnatR:

Representation information for unit P (body)
--------------------------------------------

for B_1.R'Size use 32;
for B_1.R'Alignment use 4;
for B_1.R use record
   I at 0 range  0 .. 31;
end record;

2018-05-29  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* repinfo.adb (List_Entities): Also recurse into blocks without label.

From-SVN: r260884
2018-05-29 09:42:16 +00:00
Ed Schonberg
3747db827d [Ada] Unnesting: do not generate push/pop for exceptions
2018-05-29  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_ch6.adb (Expand_N_Subprogram_Body): Do not generate push/pop for
	exceptions if subprogram unnesting is in effect, because these branch
	nodes are relevant only in the presence of nested subprograms.

From-SVN: r260883
2018-05-29 09:42:11 +00:00
Ed Schonberg
ef22a3b269 [Ada] Improper behavior of floating-point attributes
This patch fixes an error in the handling of attributes Pred qnd Succ when
applied to the limit values of a floating-point type. The RM mandates that
such operations must raise constraint_error, but GNAT generated in most cases
an infinite value, regardless of whether overflow checks were enabled.

2018-05-29  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* libgnat/s-fatgen.adb (Succ, Pred):  Raise Constraint_Error
	unconditionally when applied to the largest positive (resp. largest
	negative) value of a floating-point type.

gcc/testsuite/

	* gnat.dg/float_attributes_overflows.adb: New testcase.

From-SVN: r260882
2018-05-29 09:42:05 +00:00
Ed Schonberg
54e33e5f6a [Ada] Clarify use of Activation_Record_Component
2018-05-29  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* einfo.ads, einfo.adb: Clarify use of Activation_Record_Component:
	discriminants and exceptions are never components of such.  The flag
	Needs_Activation_Record is set on subprogram types, not on access to
	them.

From-SVN: r260881
2018-05-29 09:41:59 +00:00
Ed Schonberg
895500a2ae [Ada] Set scope of component of subtype
2018-05-29  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_ch3.adb: Set scope of component of subtype.

From-SVN: r260880
2018-05-29 09:41:52 +00:00
Ed Schonberg
14f8ba9ad1 [Ada] Unnesting: exclude selected components whose prefix carry no type
2018-05-29  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_unst.adb (Visit_Node): Exclude selected components whose prefix
	carry no type. Such selected components appear in unit names that are
	child units, both in the specification and possibly in an end label for
	the unit, and they do not contain any relevant uplevel references.

From-SVN: r260879
2018-05-29 09:41:45 +00:00
Arnaud Charlet
ec3b72c55d [Ada] Turn Ada.Calendar.Epoch_Offset into a function
2018-05-29  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* libgnat/a-calend.ads, libgnat/a-calend.adb (Epoch_Offset): Make it a
	function.

From-SVN: r260878
2018-05-29 09:41:40 +00:00
Olivier Hainque
57dfb3eca0 [Ada] Add system-vxworks7 variants of system.ads files for Vx7
Based on the Vx6 versions, using a different link spec to accomodate VxWorks 7
specificities, in particular the ability in some configurations to rely on
.ctor sections to trigger constructors in kernel modules.

2018-05-29  Olivier Hainque  <hainque@adacore.com>

gcc/ada/

	* libgnat/system-vxworks7-ppc-rtp.ads: New file.
	* libgnat/system-vxworks7-ppc-kernel.ads: New file.
	* libgnat/system-vxworks7-e500-rtp.ads: New file.
	* libgnat/system-vxworks7-e500-kernel.ads: New file.
	* libgnat/system-vxworks7-x86-rtp.ads: New file.
	* libgnat/system-vxworks-ppc64-kernel.ads: Rename as ...
	* libgnat/system-vxworks7-ppc64-kernel.ads: and adjust name of
	gnat-crtbe link spec to use the vx7 variant.

From-SVN: r260877
2018-05-29 09:41:34 +00:00
Olivier Hainque
1f39fcd651 [Ada] Tighten crtbegin files for VxWorks
Enforce a more explicit distinction of crtbegin objects holding
either functions with ctor/dtor attributes or _ctors/_dtors arrays,
or none of the two (no array, no attributes). Then allow/enforce
different linking strategies for VxWorks 7.

2018-05-29  Olivier Hainque  <hainque@adacore.com>

gcc/ada/

	* vx_crtbegin.inc: Use a consistent naming convention for the
	registration/deregistration functions across RTP or kernel.  Remove the
	ctor/dtor attribute setting based on RTP/kernel, expect the optional
	attribute extension to be provided by includers instead.
	* vx_crtbegin.c: Mere inclusion of vx_crtbegin.inc with empty attribute
	extension for the registration/deregistration functions.
	* vx_crtbegin_attr.c: New file. Include vx_crtbegin.inc with explicit
	constructor/destructor attribute extensions.
	* vx_crtbegin_array.c: New file. Include vx_crtbegin.inc with empty
	attribute extensions and declare _ctors/_dtors arrays.
	* vx_crtbegin_auto.c: Remove.
	* libgnat/system-vxworks7-aarch64-rtp-smp.ads: Use
	vxworks7-gnat-crtbe-link.spec.
	* libgnat/system-vxworks7-aarch64.ads: Likewise.
	* libgnat/system-vxworks7-e500-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-ppc-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-ppc64-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-x86-kernel.ads: Likewise.
	* libgnat/system-vxworks7-x86-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-x86_64-kernel.ads: Likewise.
	* libgnat/system-vxworks7-x86_64-rtp-smp.ads: Likewise.

From-SVN: r260876
2018-05-29 09:41:02 +00:00
Piotr Trojanek
8f1edbd3ac [Ada] Minor reformatting
2018-05-29  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* ali.adb: Minor reformatting.

From-SVN: r260875
2018-05-29 09:40:37 +00:00
Joel Brobecker
c258a5b2fa [Ada] GNAT UGN: update package requirements for 32bit GNAT on x86_64-linux
2018-05-29  Joel Brobecker  <brobecker@adacore.com>

gcc/ada/

	* doc/gnat_ugn/platform_specific_information.rst: Update package
	requirements for 32bit GNAT on x86_64-linux.
	* gnat_ugn.texi: Regenerate.

From-SVN: r260874
2018-05-29 09:40:15 +00:00
Eric Botcazou
de9b2a969e [Ada] Adjustment of behavior of new -gnatRj switch
This decouples -gnatRj from the destination, either standard output or file,
so that it only toggles the format of the representation information.

2018-05-29  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* doc/gnat_ugn/building_executable_programs_with_gnat.rst (Debugging
	Control): Adjust description of -gnatRj.
	* gnat_ugn.texi: Regenerate.
	* opt.ads (List_Representation_Info_To_JSON): Likewise.
	* repinfo.adb (List_Rep_Info): Do not automatically create a file
	if List_Representation_Info_To_JSON is true.
	* switch-c.adb (Scan_Front_End_Switches) <R>: Remove incompatibility
	check between -gnatRj and -gnatRs.
	* usage.adb (Usage): Adjust description of -gnatRj.

From-SVN: r260873
2018-05-29 09:39:44 +00:00
Pascal Obry
ce09c3c07f [Ada] Fix constraint error in Normalize_Pathname
Fix Normalize_Pathname to avoid a constraint error.

2018-05-29  Pascal Obry  <obry@adacore.com>

gcc/ada/

	* libgnat/s-os_lib.adb (Normalize_Pathname): Fix handling of ".." in
	the root directory.

gcc/testsuite/

	* gnat.dg/normalize_pathname.adb: New testcase.

From-SVN: r260872
2018-05-29 09:39:11 +00:00
Pascal Obry
ae3d5f110d [Ada] System.Os_Lib: minor reformatting
2018-05-29  Pascal Obry  <obry@adacore.com>

gcc/ada/

	* libgnat/s-os_lib.adb: Minor reformatting.

From-SVN: r260871
2018-05-29 09:38:41 +00:00
Doug Rupp
35f5e2c14a [Ada] New function to return nanoseconds from Unix Epoch
2018-05-29  Doug Rupp  <rupp@adacore.com>

gcc/ada/

	* libgnat/a-calend.adb (Epoch_Offset): Move from body to ...
	* libgnat/a-calend.ads (Epoch_Offset): to private part of spec
	* libgnat/a-calcon.ads (To_Unix_Nano_Time): New function spec.
	* libgnat/a-calcon.adb (To_Unix_Nano_Time): New function body.

From-SVN: r260870
2018-05-29 09:38:17 +00:00
Eric Botcazou
0f9ca0303e [Ada] Enhance output of discriminants with -gnatR in JSON mode
This arranges for the Discriminant_Number of discriminants to be output
by -gnatR in JSON mode.  This number is referenced in symbolic expressions
present for offsets and sizes, so its definition is also required for the
sake of completeness.

2018-05-29  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* repinfo.ads (JSON format): Document new pair for components.
	* repinfo.adb (Derived_Discriminant): New function.
	(List_Structural_Record_Layout): Add Outer_Ent parameter and pass it
	in recursive calls. If the record type is the parent of an extension,
	find and list the derived discriminant from the extension, if any.
	(List_Component_Layout): List the Discriminant_Number in JSON mode.
	(List_Record_Info): Adjust call to List_Structural_Record_Layout.

From-SVN: r260869
2018-05-29 09:37:43 +00:00
Eric Botcazou
1e7629b8a2 [Ada] Implement machine parsable format for -gnatR output
This adds a new variant to the -gnatR switch, namely -gnatRj, which causes
the compiler to output representation information to a file in the JSON
data interchange format.  It can be combined with -gnatR0/1/2/3/m (but is
incompatible with -gnaRe and -gnatRs).

The information output in this mode is a superset of that output in the
traditional -gnatR mode, but is otherwise equivalent for the common part.

2018-05-29  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* doc/gnat_ugn/building_executable_programs_with_gnat.rst (Alphabetical
	List of All Switches): Document -gnatRj.
	(Debugging Control): Likewise.
	* gnat_ugn.texi: Regenerate.
	* opt.ads (List_Representation_Info_To_JSON): New boolean variable.
	* osint-c.adb (Create_Repinfo_File): Use the .json instead of .rep
	extension if List_Representation_Info_To_JSON is true.
	* repinfo.ads: Document the JSON output format.
	* repinfo.adb (List_Location): New procedure.
	(List_Array_Info): Add support for JSON output.
	(List_Entities): Likewise.
	(Unop): Likewise.
	(Binop): Likewise.
	(Print_Expr): Likewise.
	(List_Linker_Section): Likewise.
	(List_Mechanisms): Likewise.
	(List_Name): Likewise.
	(List_Object_Info): Likewise.
	(List_Record_Info): Likewise.
	(List_Component_Layout): Likewise.  Add Indent parameter.
	(List_Structural_Record_Layout): New procedure.
	(List_Attr): Add support for JSON output.
	(List_Type_Info): Likewise.
	(Write_Unknown_Val): Likewise.
	* switch-c.adb (Scan_Front_End_Switches) <R>: Deal with 'j'.
	* usage.adb (Usage): List -gnatRj.

From-SVN: r260868
2018-05-29 09:36:51 +00:00
Eric Botcazou
7883c42e3f [Ada] Factor out worker procedure for -gnatR
This extracts a worker procedure for printing the layout of a single component
from List_Record_Layout so as to make the next change more readable.

2018-05-29  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* repinfo.adb (List_Component_Layout): New procedure extracted from...
	(List_Record_Layout): ...here.  Invoke it.

From-SVN: r260867
2018-05-29 09:36:34 +00:00
Eric Botcazou
76b382d9a0 [Ada] Minor cleanup in repinfo unit
This factors out the various cases where a marker for an unknown value is
output by the -gnatR switches.  No functional changes.

2018-05-29  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* repinfo.adb (Write_Unknown_Val): New procedure.
	(List_GCC_Expression): Call it.
	(List_Record_Layout): Likewise.
	(Write_Val): Likewise.

From-SVN: r260866
2018-05-29 09:35:57 +00:00
Richard Kenner
c35c40e7f6 [Ada] Clear Do_Overflow_Check when inserting code to do check
2018-05-29  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

gcc/ada/

	* exp_ch4.adb (Expand_N_Op_Abs): Clear Do_Overflow_Check when inserting
	code to do check.

From-SVN: r260865
2018-05-29 09:35:25 +00:00