Commit Graph

171510 Commits

Author SHA1 Message Date
Ed Schonberg b8411279b0 [Ada] Crash on aggregate with dscriminant in if-expression as default
This patch fixes a crash on a an aggregate for a discriminated type,
when a component of the aggregate is also a discriminated type
constrained by a discriminant of the enclosing object, and the default
value for the component is a conditional expression that includes
references to that outer discriminant.

2019-09-18  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_aggr.adb (Expand_Record_Aggregate, Rewrite_Discriminant):
	After rewriting a reference to an outer discriminant as a
	selected component of the enclosing object, analyze the selected
	component to ensure that the entity of the selector name is
	properly set. This is necessary when the aggregate appears
	within an expression that may have been analyzed already.

gcc/testsuite/

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

From-SVN: r275862
2019-09-18 08:33:27 +00:00
Justin Squirek 483af72e4b [Ada] Spurious ineffective use_clause warning
This patch fixes an issue whereby expansion of post conditions may lead
to spurious ineffective use_clause warnings when a use type clause is
present in a package specification and a use package clause exists in
the package body on the package containing said type.

2019-09-18  Justin Squirek  <squirek@adacore.com>

gcc/ada/

	* sem_ch8.adb (Use_One_Type): Add guard to prevent warning on a
	reundant use package clause where there is no previous
	use_clause in the chain.

gcc/testsuite/

	* gnat.dg/warn30.adb, gnat.dg/warn30.ads: New testcase.

From-SVN: r275861
2019-09-18 08:33:23 +00:00
Justin Squirek 1b2f53bb9a [Ada] Missing accessibility check on discrim assignment
This patch fixes an issue whereby assignments from anonymous access
descriminants which are part of stand alone objects of anonymous access
did not have runtime checks generated based on the accessibility level
of the object according to ARM 3.10.2 (12.5/3).

2019-09-18  Justin Squirek  <squirek@adacore.com>

gcc/ada/

	* exp_ch4.adb (Expand_N_Type_Conversion): Add calculation of an
	alternative operand for the purposes of generating accessibility
	checks.

gcc/testsuite/

	* gnat.dg/access8.adb, gnat.dg/access8_pkg.adb,
	gnat.dg/access8_pkg.ads: New testcase.

From-SVN: r275860
2019-09-18 08:33:17 +00:00
Eric Botcazou 6951cbc9e7 [Ada] Fix sharing of expression in array aggregate with others choice
This change fixes a long-standing issue in the compiler that is
generally silent but may lead to wrong code generation in specific
circumstances.  When an others choice in an array aggregate spans
multiple ranges, the compiler may generate multiple (groups of)
assignments for the ranges.

The problem is that it internally reuses the original expression for all
the ranges, which is problematic if this expression gets rewritten
during the processing of one of the ranges and typically causes a new
temporary to be shared between different ranges.

The solution is to duplicate the original expression for each range.

2019-09-18  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* exp_aggr.adb (Build_Array_Aggr_Code): In STEP 1 (c), duplicate
	the expression and reset the Loop_Actions for each loop
	generated for an others choice.

gcc/testsuite/

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

From-SVN: r275859
2019-09-18 08:33:12 +00:00
Justin Squirek 43b264110f [Ada] Spurious run time error on anonymous access formals
This patch fixes an issue whereby subprograms with anonymous access
formals may trigger spurious runtime accessibility errors when such
formals are used as actuals in calls to nested subprograms.

Running these commands:

  gnatmake -q pass.adb
  gnatmake -q fail.adb
  gnatmake -q test_main.adb
  gnatmake -q indirect_call_test.adb
  pass
  fail
  test_main
  indirect_call_test

On the following sources:

--  pass.adb

procedure Pass is

  function A (Param : access Integer) return Boolean is
    type Typ is access all Integer;
    function A_Inner (Param : access Integer) return Typ is
      begin
        return Typ (Param); --  OK
      end;
    begin
      return A_Inner (Param) = Typ (Param);
    end;

  function B (Param : access Integer) return Boolean;
  function B (Param : access Integer) return Boolean is
    type Typ is access all Integer;
    function B_Inner (Param : access Integer) return Typ is
      begin
        return Typ (Param); --  OK
      end;
    begin
      return B_Inner (Param) = Typ (Param);
    end;

  procedure C (Param : access Integer) is
    type Typ is access all Integer;
    Var : Typ;
    procedure C_Inner (Param : access Integer) is
      begin
        Var := Typ (Param); --  OK
      end;
    begin
      C_Inner (Param);
    end;

  procedure D (Param : access Integer);
  procedure D (Param : access Integer) is
    type Typ is access all Integer;
    Var : Typ;
    procedure D_Inner (Param : access Integer) is
      begin
        Var := Typ (Param); --  OK
      end;
    begin
      D_Inner (Param);
    end;

  protected type E is
    function G (Param : access Integer) return Boolean;
    procedure I (Param : access Integer);
  end;

  protected body E is
    function F (Param : access Integer) return Boolean is
      type Typ is access all Integer;
      function F_Inner (Param : access Integer) return Typ is
        begin
          return Typ (Param); --  OK
        end;
      begin
        return F_Inner (Param) = Typ (Param);
      end;

    function G (Param : access Integer) return Boolean is
      type Typ is access all Integer;
      function G_Inner (Param : access Integer) return Typ is
        begin
          return Typ (Param); --  OK
        end;
      B : Boolean := F (Param); --  OK
      begin
        return G_Inner (Param) = Typ (Param);
      end;

    procedure H (Param : access Integer) is
      type Typ is access all Integer;
      Var : Typ;
      procedure H_Inner (Param : access Integer) is
        begin
          Var := Typ (Param); --  OK
        end;
      begin
        H_Inner (Param);
      end;

    procedure I (Param : access Integer) is
      type Typ is access all Integer;
      Var : Typ;
      procedure I_Inner (Param : access Integer) is
        begin
          Var := Typ (Param); --  OK
        end;
      begin
        H (Param); --  OK
        I_Inner (Param);
      end;
  end;

  task type J is end;

  task body J is
    function K (Param : access Integer) return Boolean is
      type Typ is access all Integer;
      function K_Inner (Param : access Integer) return Typ is
        begin
          return Typ (Param); --  OK
        end;
      begin
        return K_Inner (Param) = Typ (Param);
      end;

    function L (Param : access Integer) return Boolean;
    function L (Param : access Integer) return Boolean is
      type Typ is access all Integer;
      function L_Inner (Param : access Integer) return Typ is
        begin
          return Typ (Param); --  OK
        end;
      begin
        return L_Inner (Param) = Typ (Param);
      end;

    procedure M (Param : access Integer) is
      type Typ is access all Integer;
      Var : Typ;
      procedure M_Inner (Param : access Integer) is
        begin
          Var := Typ (Param); --  OK
        end;
      begin
        M_Inner (Param);
      end;

    procedure N (Param : access Integer);
    procedure N (Param : access Integer) is
      type Typ is access all Integer;
      Var : Typ;
      procedure N_Inner (Param : access Integer) is
        begin
          Var := Typ (Param); --  OK
        end;
      begin
        N_Inner (Param);
      end;
    Var : aliased Integer := 666;
    begin
      if K (Var'Access) then null; end if; --  OK
      if L (Var'Access) then null; end if; --  OK
      M (Var'Access);                      --  OK
      N (Var'Access);                      --  OK
    end;

begin
  begin
    begin
      declare
      Var  : aliased Integer := 666;
      T    : J;
      Prot : E;
      begin
        if A (Var'Access) then null; end if;      --  OK
        if B (Var'Access) then null; end if;      --  OK
        C (Var'Access);                           --  OK
        D (Var'Access);                           --  OK
        if Prot.G (Var'Access) then null; end if; --  OK
        Prot.I (Var'Access);                      --  OK
      end;
    end;
  end;
end;

--  fail.adb

procedure Fail is
  Failures : Integer := 0;

  type Base_Typ is access all Integer;

  function A (Param : access Integer) return Boolean is
    subtype Typ is Base_Typ;
    function A_Inner (Param : access Integer) return Typ is
      begin
        return Typ (Param); --  ERROR
      end;
    begin
      return A_Inner (Param) = Typ (Param);
    exception
      when others => Failures := Failures + 1;
      return False;
    end;

  function B (Param : access Integer) return Boolean;
  function B (Param : access Integer) return Boolean is
    subtype Typ is Base_Typ;
    function B_Inner (Param : access Integer) return Typ is
      begin
        return Typ (Param); --  ERROR
      end;
    begin
      return B_Inner (Param) = Typ (Param);
    exception
      when others => Failures := Failures + 1;
      return False;
    end;

  procedure C (Param : access Integer) is
    subtype Typ is Base_Typ;
    Var : Typ;
    procedure C_Inner (Param : access Integer) is
      begin
        Var := Typ (Param); --  ERROR
      end;
    begin
      C_Inner (Param);
    exception
      when others => Failures := Failures + 1;
    end;

  procedure D (Param : access Integer);
  procedure D (Param : access Integer) is
    subtype Typ is Base_Typ;
    Var : Typ;
    procedure D_Inner (Param : access Integer) is
      begin
        Var := Typ (Param); --  ERROR
      end;
    begin
      D_Inner (Param);
    exception
      when others => Failures := Failures + 1;
    end;

  protected type E is
    function G (Param : access Integer) return Boolean;
    procedure I (Param : access Integer);
  end;

  protected body E is
    function F (Param : access Integer) return Boolean is
      subtype Typ is Base_Typ;
      function F_Inner (Param : access Integer) return Typ is
        begin
          return Typ (Param); --  ERROR
        end;
      begin
        return F_Inner (Param) = Typ (Param);
      exception
        when others => Failures := Failures + 1;
        return False;
      end;

    function G (Param : access Integer) return Boolean is
      subtype Typ is Base_Typ;
      function G_Inner (Param : access Integer) return Typ is
        begin
          return Typ (Param); --  ERROR
        end;
      B : Boolean := F (Param); --  ERROR
      begin
        return G_Inner (Param) = Typ (Param);
      exception
        when others => Failures := Failures + 1;
        return False;
      end;

    procedure H (Param : access Integer) is
      subtype Typ is Base_Typ;
      Var : Typ;
      procedure H_Inner (Param : access Integer) is
        begin
          Var := Typ (Param); --  ERROR
        end;
      begin
        H_Inner (Param);
      exception
        when others => Failures := Failures + 1;
      end;

    procedure I (Param : access Integer) is
      subtype Typ is Base_Typ;
      Var : Typ;
      procedure I_Inner (Param : access Integer) is
        begin
          Var := Typ (Param); --  ERROR
        end;
      begin
        H (Param); --  ERROR
        I_Inner (Param);
      exception
        when others => Failures := Failures + 1;
      end;
  end;

  task type J is end;

  task body J is
    function K (Param : access Integer) return Boolean is
      subtype Typ is Base_Typ;
      function K_Inner (Param : access Integer) return Typ is
        begin
          return Typ (Param); --  ERROR
        end;
      begin
        return K_Inner (Param) = Typ (Param);
      exception
        when others => Failures := Failures + 1;
        return False;
      end;

    function L (Param : access Integer) return Boolean;
    function L (Param : access Integer) return Boolean is
      subtype Typ is Base_Typ;
      function L_Inner (Param : access Integer) return Typ is
        begin
          return Typ (Param); --  ERROR
        end;
      begin
        return L_Inner (Param) = Typ (Param);
      exception
        when others => Failures := Failures + 1;
        return False;
      end;

    procedure M (Param : access Integer) is
      subtype Typ is Base_Typ;
      Var : Typ;
      procedure M_Inner (Param : access Integer) is
        begin
          Var := Typ (Param); --  ERROR
        end;
      begin
        M_Inner (Param);
      exception
        when others => Failures := Failures + 1;
      end;

    procedure N (Param : access Integer);
    procedure N (Param : access Integer) is
      subtype Typ is Base_Typ;
      Var : Typ;
      procedure N_Inner (Param : access Integer) is
        begin
          Var := Typ (Param); --  ERROR
        end;
      begin
        N_Inner (Param);
      exception
        when others => Failures := Failures + 1;
      end;
    Var : aliased Integer := 666;
    begin
      if K (Var'Access) then null; end if; --  ERROR
      if L (Var'Access) then null; end if; --  ERROR
      M (Var'Access);                      --  ERROR
      N (Var'Access);                      --  ERROR
    end;

begin
  begin
    begin
      declare
      Var  : aliased Integer := 666;
      T    : J;
      Prot : E;
      begin
        if A (Var'Access) then null; end if;      --  ERROR
        if B (Var'Access) then null; end if;      --  ERROR
        C (Var'Access);                           --  ERROR
        D (Var'Access);                           --  ERROR
        if Prot.G (Var'Access) then null; end if; --  ERROR
        Prot.I (Var'Access);                      --  ERROR
        if Failures /= 12 then
          raise Program_Error;
        end if;
      end;
    end;
  end;
end;

--  indirect_call_test.adb

with Text_IO;

procedure Indirect_Call_Test is

   Tracing_Enabled : constant Boolean := False;
   procedure Trace (S : String) is
   begin
      if Tracing_Enabled then
        Text_IO.Put_Line (S);
      end if;
   end;

   package Pkg is
      type Root is abstract tagged null record;
      function F (X : Root; Param : access Integer)
        return Boolean is abstract;
   end Pkg;

   function F_Wrapper
     (X : Pkg.Root; Param : access Integer)
     return Boolean
     is (Pkg.F (Pkg.Root'Class (X), Param));
     -- dispatching call

   function A (Param : access Integer) return Boolean is
      type Typ is access all Integer;

      package Nested is
         type Ext is new Pkg.Root with null record;
         overriding function F
           (X : Ext; Param : access Integer)
           return Boolean;
      end Nested;

      function A_Inner
        (Param : access Integer) return Typ is
      begin
         return Typ (Param);  -- OK
      end A_Inner;

      package body Nested is
         function F (X : Ext; Param : access Integer)
          return Boolean is
         begin
            return A_Inner (Param) = null;
         end;
      end;

       Ext_Obj : Nested.Ext;
   begin
       Trace ("In subtest A");
       return F_Wrapper (Pkg.Root (Ext_Obj), Param);
   exception
      when Program_Error =>
          Trace ("Failed");
          return True;
   end A;

   function B (Param : access Integer) return Boolean is
      type Typ is access all Integer;

      function B_Inner
        (Param : access Integer) return Typ is
      begin
         return Typ (Param); -- OK
      end B_Inner;

      type Ref is access function
         (Param : access Integer) return Typ;
      Ptr : Ref := B_Inner'Access;

      function Ptr_Caller return Typ is
        (Ptr.all (Param)); -- access-to-subp value
   begin
      Trace ("In subtest B");
      return Ptr_Caller = null;
   exception
      when Program_Error =>
          Trace ("*** failed");
          return True;
   end B;

begin
   begin
      begin
         declare
            Var : aliased Integer := 666;
         begin
            if A (Var'Access) then
               null;
            end if;
            Trace ("Subtest A done");
            if B (Var'Access) then
               null;
            end if;
            Trace ("Subtest B done");
         end;
      end;
   end;
end Indirect_Call_Test;

Should produce the following output:

  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure
  Failure

2019-09-18  Justin Squirek  <squirek@adacore.com>

gcc/ada/

	* einfo.adb, einfo.ads (Minimum_Accessibility): Added new field.
	(Set_Minimum_Accessibility): Added to set new field.
	(Minimum_Accessibility): Added to fetch new field.
	* exp_ch6.adb (Expand_Subprogram_Call): Modify calls to fetch
	accessibility levels to the new subprogram Get_Accessibility
	which handles cases where minimum accessibility might be needed.
	* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Add section to
	generate a Minimum_Accessibility object within relevant
	subprograms.
	* sem_util.adb, sem_util.ads (Dynamic_Accessibility_Level):
	Additional documentation added and modify section to use new
	function Get_Accessibility.
	(Get_Accessibility): Added to centralize processing of
	accessibility levels.

From-SVN: r275858
2019-09-18 08:33:07 +00:00
Steve Baird c8324fe7b1 [Ada] Implement AI12-0086's rules for discriminants in aggregates
In Ada2012, a discriminant value that governs an active variant part in
an aggregate had to be static. AI12-0086 relaxes this restriction - if
the subtype of the discriminant value is a static subtype all of whose
values select the same variant, then that is good enough.

2019-09-18  Steve Baird  <baird@adacore.com>

gcc/ada/

	* sem_util.ads (Interval_Lists): A new visible package. This
	package is visible because it is also intended for eventual use
	in Sem_Eval.Subtypes_Statically_Compatible when that function is
	someday upgraded to handle static predicates correctly.  This
	new package doesn't really need to be visible for now, but it
	still seems like a good idea.
	* sem_util.adb (Gather_Components): Implement AI12-0086 via the
	following strategy. The existing code knows how to take a static
	discriminant value and identify the corresponding variant; in
	the newly-permitted case of a non-static value of a static
	subtype, we arbitrarily select a value of the subtype and find
	the corresponding variant using the existing code. Subsequently,
	we check that every other value of the discriminant's subtype
	corresponds to the same variant; this is done using the newly
	introduced Interval_Lists package.
	(Interval_Lists): Provide a body for the new package.

gcc/testsuite/

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

From-SVN: r275857
2019-09-18 08:33:02 +00:00
Javier Miranda 6bc08721d0 [Ada] Fix portability issues in access to subprograms
This patch improves the portability of the code generated by the
compiler for access to subprograms. Written by Richard Kenner.

2019-09-18  Javier Miranda  <miranda@adacore.com>

gcc/ada/

	* exp_ch4.adb (Expand_N_Op_Eq): The frontend assumes that we can
	do a bit-for-bit comparison of two access to protected
	subprogram pointers. However, there are two reasons why we may
	not be able to do that: (1) there may be padding bits for
	alignment before the access to subprogram, and (2) the access to
	subprogram itself may not be compared bit-for- bit because the
	activation record part is undefined: two pointers are equal iff
	the subprogram addresses are equal. This patch fixes it by
	forcing a field-by-field comparison.
	* bindgen.adb (Gen_Adainit): The type No_Param_Proc is defined
	in the library as having Favor_Top_Level, but when we create an
	object of that type in the binder file we don't have that
	pragma, so the types are different. This patch fixes this issue.
	* libgnarl/s-interr.adb, libgnarl/s-interr__hwint.adb,
	libgnarl/s-interr__sigaction.adb, libgnarl/s-interr__vxworks.adb
	(Is_Registered): This routine erroneously assumes that the
	access to protected subprogram is two addresses. We need to
	create the same record that the compiler makes to ensure that
	any padding is the same. Then we have to look at just the first
	word of the access to subprogram. This patch fixes this issue.

From-SVN: r275856
2019-09-18 08:32:55 +00:00
Bob Duff 0af1653524 [Ada] Improve efficiency of copying bit-packed slices
This patch substantially improves the efficiency of copying large slices
of bit-packed arrays, by copying 32 bits at a time instead of 1 at a
time.

2019-09-18  Bob Duff  <duff@adacore.com>

gcc/ada/

	* exp_ch5.adb (Expand_Assign_Array_Loop_Or_Bitfield): The call
	to Copy_Bitfield is now enabled.
	(Expand_Assign_Array_Bitfield): Multiply 'Length times
	'Component_Size "by hand" instead of using 'Size.

From-SVN: r275855
2019-09-18 08:32:51 +00:00
Vasiliy Fofanov a6d677c65b [Ada] Fix minor formatting issue
2019-09-18  Vasiliy Fofanov  <fofanov@adacore.com>

gcc/ada/

	* doc/gnat_rm/implementation_defined_pragmas.rst: Fix minor
	formatting issue.

From-SVN: r275854
2019-09-18 08:32:46 +00:00
Javier Miranda f04e9787ea [Ada] Code cleanup of alignment representation clauses in dispatch tables
This patch does not modify the functionality of the compiler; it avoids
generating non-required alignment representation clauses for dispatch
tables.

2019-09-18  Javier Miranda  <miranda@adacore.com>

gcc/ada/

	* exp_disp.adb (Make_DT, Make_Secondary_DT): Remove generation
	of alignment representation clause for the following tables:
	Predef_Prims, Iface_DT, TSD, ITable, DT.

From-SVN: r275853
2019-09-18 08:32:42 +00:00
Steve Baird 50a7395372 [Ada] Don't fail a front-end assertion if errors have already been detected
In sem_eval.adb, we have an assertion that the type of a "null" literal
is an access type. It turns out that this assertion can fail when
processing an illegal program, e.g. one that contains something like
"Integer'(null)".  This leads to differences in the compiler's generated
output for such tests depending on whether assertions are/aren't
enabled; in particular, the "compilation abandoned due to previous
error" message generated in Comperr.Compiler_Abort. In order to avoid
these differences, we change the assertion so that it does not fail if
errors have already been posted on the given node.

2019-09-18  Steve Baird  <baird@adacore.com>

gcc/ada/

	* sem_eval.adb (Expr_Value): Do not fail "the type of a null
	literal must be an access type" assertion if errors have already
	been posted on the given node.

From-SVN: r275852
2019-09-18 08:32:37 +00:00
Piotr Trojanek 432a3b3644 [Ada] Refine type of Get_Homonym_Number result
Routine Get_Homonym_Number always returns a positive number. This is
explained in its comment and is evident from its body. No test attached,
because semantics is unaffected.

2019-09-18  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* exp_dbug.ads, exp_dbug.adb (Get_Homonym_Number): Refine type
	from Nat to Pos.
	* sem_util.adb (Add_Homonym_Suffix): Refine type of a local
	variable.

From-SVN: r275851
2019-09-18 08:32:33 +00:00
Yannick Moy d05586dce2 [Ada] Skip entity name qualification in GNATprove mode
GNATprove was using the qualification of names for entities with local
homonyms in the same scope, requiring the use of a suffix to
differentiate them. This caused problems for correctly identifying
primitive equality operators. This case is now handled like the rest of
entities in GNATprove, by instead updating Unique_Name to append the
suffix on-the-fly where needed.

There is no impact on compilation and hence no test.

2019-09-18  Yannick Moy  <moy@adacore.com>

gcc/ada/

	* exp_dbug.adb (Append_Homonym_Number): Use new function
	Get_Homonym_Number.
	(Get_Homonym_Number): New function to return the homonym number.
	(Qualify_Entity_Name): Remove special case for GNATprove.
	* exp_dbug.ads (Get_Homonym_Number): Make the new function
	public for use in GNATprove.
	* frontend.adb (Frontend): Do not qualify names in GNATprove
	mode.
	* sem_util.adb (Unique_Name): Append homonym suffix where needed
	for entities which have local homonyms in the same scope.

From-SVN: r275850
2019-09-18 08:32:28 +00:00
Nicolas Roche b67723ddee [Ada] Ensure that Scan_Real result does not depend on trailing zeros
Previous change in that procedure to handle overflow issues during
scanning removed the special handling for trailing zeros in the decimal
part. Beside the absence of overflow during scanning the special
handling of these zeros is still necessary.

2019-09-18  Nicolas Roche  <roche@adacore.com>

gcc/ada/

	* libgnat/s-valrea.adb (Scan_Integral_Digits): New procedure.
	(Scan_Decimal_Digits): New procedure.
	(As_Digit): New function.
	(Scan_Real): Use Scan_Integral_Digits and Scan_Decimal_Digits.

gcc/testsuite/

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

From-SVN: r275849
2019-09-18 08:32:23 +00:00
Claire Dross d2880e6954 [Ada] Factor out code for deciding statically known Constrained attributes
Create a separate routine in Exp_Util for deciding the value of the
Constrained attribute when it is statically known. This routine is used
in Exp_Attr and will be reused in the backend of GNATprove.

There is no impact on compilation and hence no test.

2019-09-18  Claire Dross  <dross@adacore.com>

gcc/ada/

	* exp_attr.adb (Expand_N_Attribute_Reference): Call routine from
	Exp_Util to know the value of the Constrained attribute in the
	static case.
	* exp_spark.adb (Expand_SPARK_N_Attribute_Reference): Make
	implicit dereferences inside the Constrained attribute explicit.
	* exp_util.ads, exp_util.adb
	(Attribute_Constrained_Static_Value): New routine to compute the
	value of a statically known reference to the Constrained
	attribute.

From-SVN: r275848
2019-09-18 08:32:19 +00:00
Vadim Godunko 209a0094c4 [Ada] Raise exception on call to Expect for a dead process
Call to Expect for a dead process results in SIGBUS signal on Linux
systems. Process_Died exception is raised in this case now.

2019-09-18  Vadim Godunko  <godunko@adacore.com>

gcc/ada/

	* libgnat/g-expect.adb (Expect_Internal): Don't include invalid
	file descriptors into the set of file descriptors for Poll.
	Raise Process_Died exception when computed set of file
	descriptors to monitor is empty.

gcc/testsuite/

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

From-SVN: r275847
2019-09-18 08:32:14 +00:00
Frederic Konrad 82fa20a211 [Ada] Fix errno for rename for the VxWorks 6 target
This fixes the wrong errno for rename when the file is not existing on a
dosFs. In the end it makes Ada.Directories.Rename raising the right
exception in the case we are trying to move a file in a non existing
directory.

2019-09-18  Frederic Konrad  <konrad@adacore.com>

gcc/ada/

	* adaint.c: Include dosFsLib.h and vwModNum.h for VxWorks 6.
	(__gnat_rename): Map S_dosFsLib_FILE_NOT_FOUND to ENOENT.

From-SVN: r275846
2019-09-18 08:32:09 +00:00
Steve Baird dcbe49a6c4 [Ada] No Storage_Error for an oversized disabled ghost array object
In some cases where the size computation for an object declaration will
unconditionally overflow, the FE generates code to raise Storage_Error
at the point of the object declaration (and may generate an associated
warning). Don't do this if the object declaration is an ignored (i.e.,
disabled) ghost declaration.

2019-09-18  Steve Baird  <baird@adacore.com>

gcc/ada/

	* freeze.adb (Freeze_Object_Declaration): Do not call
	Check_Large_Modular_Array when the object declaration being
	frozen is an ignored ghost entity.

gcc/testsuite/

	* gnat.dg/ghost7.adb, gnat.dg/ghost7.ads: New testcase.

From-SVN: r275845
2019-09-18 08:32:05 +00:00
Tom Tromey e42183e72b [Ada] Fix typo in error message
An error message mentions "gnamake", where it meant to mention
"gnatmake".

2019-09-18  Tom Tromey  <tromey@adacore.com>

gcc/ada/

	* make.adb (Initialize): Fix typo.

From-SVN: r275844
2019-09-18 08:32:00 +00:00
Olivier Hainque 600db6ca89 [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
The dwActiveProcessorMask field in a SYSTEM_INFO structure on Windows
should be DWORD_PTR, an integer the size of a pointer.

In s-win32, it is currently declared as DWORD. This happens to work on
32bit hosts and is wrong on 64bit hosts, causing mishaps in accesses to
this component and all the following ones.

The proposed correction adds a definition for DWORD_PTR and uses it for
dwActiveProcessorMask in System.Win32.SYSTEM_INFO.

2019-09-18  Olivier Hainque  <hainque@adacore.com>

gcc/ada/

	* libgnat/s-win32.ads (DWORD_PTR): New type, pointer size
	unsigned int.
	(SYSTEM_INFO): Use it for dwActiveProcessorMask.

gcc/testsuite/

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

From-SVN: r275843
2019-09-18 08:31:56 +00:00
Arnaud Charlet 6f934861c1 [Ada] Improve doc on Warning_As_Error
2019-09-18  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* doc/gnat_rm/implementation_defined_pragmas.rst: Improve doc on
	Warning_As_Error.
	* gnat_rm.texi: Regenerate.

From-SVN: r275842
2019-09-18 08:31:51 +00:00
Arnaud Charlet e58fc8977c [Ada] Remove remaining references to VMS support
2019-09-18  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* doc/gnat_rm/implementation_defined_characteristics.rst,
	doc/gnat_rm/implementation_defined_pragmas.rst,
	doc/gnat_rm/implementation_of_specific_ada_features.rst: Remove
	remaining references to VMS support
	* gnat_rm.texi: Regenerate.

From-SVN: r275841
2019-09-18 08:31:46 +00:00
Arnaud Charlet aeb68a2b47 [Ada] System.Stack_Usage: fix a typo
2019-09-18  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* libgnat/s-stausa.adb: Fix a typo

From-SVN: r275840
2019-09-18 08:31:42 +00:00
Bob Duff 5ce1c7733b [Ada] Avoid uninitialized variable in bounded containers
In function Copy in Ada.Containers.Bounded_Ordered_Sets and other
bounded containers packages, remove a possible use of an uninitialized
variable. This was not a bug, because the uninitialized variable could
be used only if checks are suppressed, and the checks would have failed,
leading to erroneous execution.

However, it seems more robust this way, and is probably equally
efficient, and avoids a warning that is given if checks are suppressed,
and the -Wall switch is given, and optimization is turned on.

2019-09-18  Bob Duff  <duff@adacore.com>

gcc/ada/

	* libgnat/a-cbhama.adb, libgnat/a-cbhase.adb,
	libgnat/a-cbmutr.adb, libgnat/a-cborma.adb,
	libgnat/a-cborse.adb, libgnat/a-cobove.adb (Copy): Avoid reading
	the uninitialized variable C in the Checks = False case. Change
	variable to be a constant.

gcc/testsuite/

	* gnat.dg/containers1.adb, gnat.dg/containers1.ads: New
	testcase.

From-SVN: r275839
2019-09-18 08:31:37 +00:00
Claire Dross 2b6cd96251 [Ada] Fix style issues in functional maps
Rename global constants from I to J. No functional changes.

2019-09-18  Claire Dross  <dross@adacore.com>

gcc/ada/

	* libgnat/a-cofuma.adb (Remove, Elements_Equal_Except,
	Keys_Included, Keys_Included_Except): Rename loop indexes and
	global constants from I to J.

From-SVN: r275838
2019-09-18 08:31:32 +00:00
Arnaud Charlet 2778553904 [Ada] Refine previous change for -gnatn and LLVM
2019-09-18  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* exp_unst.adb (Unnest_Subprograms): Refine previous change.

From-SVN: r275837
2019-09-18 08:31:27 +00:00
Richard Sandiford ad4644f378 [x86] Tweak testcases for PR82361
gcc/testsuite/gcc.target/i386/pr82361-[12].c check whether we
can optimise away a 32-to-64-bit zero extension of a 32-bit
division or modulus result.  Currently this fails for the modulus
part of f1 and f2 in pr82361-1.c:

/* FIXME: We are still not able to optimize the modulo in f1/f2, only manage
   one.  */
/* { dg-final { scan-assembler-times "movl\t%edx" 2 } } */

pr82361-2.c instead expects no failures:

/* Ditto %edx to %rdx zero extensions.  */
/* { dg-final { scan-assembler-not "movl\t%edx, %edx" } } */

But we actually get the same zero-extensions for f1 and f2 in pr82361-2.c.
The reason they don't trigger a failure is that the RA allocates the
asm input for "d" to %rdi rather than %rdx, so we have:

	movl	%rdx, %rdi

instead of:

	movl	%rdx, %rdx

For the tests to work as expected, I think they have to force "c" and
"d" to be %rax and %rdx respectively.  We then see the same failure in
pr82361-2.c as for pr82361-1.c (but doubled, due to the 8-bit division
path).

2019-09-18  Richard Sandiford  <richard.sandiford@arm.com>

gcc/testsuite/
	* gcc.target/i386/pr82361-1.c (f1, f2, f3, f4, f5, f6): Force
	"c" to be in %rax and "d" to be in %rdx.
	* gcc.target/i386/pr82361-2.c: Expect 4 instances of "movl\t%edx".

From-SVN: r275836
2019-09-18 07:38:32 +00:00
GCC Administrator 6a6341917f Daily bump.
From-SVN: r275833
2019-09-18 00:16:15 +00:00
Ian Lance Taylor 7e6fecf500 runtime: for FFI, treat directIface types as pointers
This only matters on systems that pass a struct with a single pointer
    field differently than passing a single pointer.  I noticed it on
    32-bit PPC, where the reflect package TestDirectIfaceMethod failed.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/195878

From-SVN: r275814
2019-09-17 20:26:21 +00:00
Ian Lance Taylor 033425d0ed re PR go/91781 (r275691 breaks go test "reflect")
PR go/91781
    reflect: promote integer closure return to full word
    
    The libffi library expects an integer return type to be promoted to a
    full word.  Implement that when returning from a closure written in Go.
    This only matters on big-endian systems when returning an integer smaller
    than the pointer size, which is why we didn't notice it until now.
    
    Fixes https://gcc.gnu.org/PR91781.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/195858

From-SVN: r275813
2019-09-17 20:24:00 +00:00
Ian Lance Taylor 99a28ee8c1 reflect: unexport FFICallbackGo; use go:linkname instead
The function was always intended to be internal-only, but was exported
    so that C code could call it. Now that have go:linkname for that, use it.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/195857

From-SVN: r275809
2019-09-17 17:22:18 +00:00
Richard Sandiford d0bc0cb66b [arm][aarch64] Handle no_insn in TARGET_SCHED_VARIABLE_ISSUE
Since no_insn patterns expand to no instructions, they shouldn't
count against the issue rate, just like USEs and CLOBBERs don't.

2019-09-17  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* config/aarch64/aarch64.c (aarch64_sched_variable_issue): New
	function.
	(TARGET_SCHED_VARIABLE_ISSUE): New macro.
	* config/arm/arm.c (arm_sched_variable_issue): New function.
	(TARGET_SCHED_VARIABLE_ISSUE): New macro.

From-SVN: r275808
2019-09-17 17:01:10 +00:00
Richard Sandiford f62281dc1b [arm][aarch64] Make no_insn issue to nothing
no_insn is documented as:

  an insn which does not represent an instruction in the final output,
  thus having no impact on scheduling.

and is used in that way by the arm port (e.g. for define_insns that
expand to comments).  However, most scheduling descriptions instead
assigned units to no_insn patterns, in some cases treating them as more
expensive than a plain move.

This patch removes the no_insn handling from individual scheduling
descriptions and uses a common define_insn_reservation for all CPUs.

2019-09-17  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* config/arm/types.md (no_reservation): New reservation.
	* config/aarch64/falkor.md (falkor_other_0_nothing): Don't handle
	no_insn here.
	* config/aarch64/saphira.md (saphira_other_0_nothing): Likewise.
	* config/aarch64/thunderx2t99.md (thunderx2t99_nothing): Likewise.
	* config/aarch64/tsv110.md (tsv110_alu): Likewise.
	* config/arm/arm1020e.md (1020alu_op): Likewise.
	* config/arm/arm1026ejs.md (alu_op): Likewise.
	* config/arm/arm1136jfs.md (11_alu_op): Likewise.
	* config/arm/arm926ejs.md (9_alu_op): Likewise.
	* config/arm/cortex-a15.md (cortex_a15_alu): Likewise.
	* config/arm/cortex-a17.md (cortex_a17_alu): Likewise.
	* config/arm/cortex-a5.md (cortex_a5_alu): Likewise.
	* config/arm/cortex-a53.md (cortex_a53_alu): Likewise.
	* config/arm/cortex-a57.md (cortex_a57_alu): Likewise.
	* config/arm/cortex-a7.md (cortex_a7_alu_shift): Likewise.
	* config/arm/cortex-a8.md (cortex_a8_alu): Likewise.
	* config/arm/cortex-a9.md (cortex_a9_dp): Likewise.
	* config/arm/cortex-m4.md (cortex_m4_alu): Likewise.
	* config/arm/cortex-m7.md (cortex_m7_alu_simple): Likewise.
	* config/arm/cortex-r4.md (cortex_r4_alu_shift_reg): Likewise.
	* config/arm/fa526.md (526_alu_op): Likewise.
	* config/arm/fa606te.md (606te_alu_op): Likewise.
	* config/arm/fa626te.md (626te_alu_op): Likewise.
	* config/arm/fa726te.md (726te_alu_op): Likewise.
	* config/arm/xgene1.md (xgene1_nop): Likewise.

From-SVN: r275807
2019-09-17 17:00:58 +00:00
Richard Sandiford 5d4efa795e [arm] Fix insn type of *thumb1_tablejump
*thumb1_tablejump had type "no_insn", which doesn't seems to correspond
to its documented use:

  an insn which does not represent an instruction in the final output,
  thus having no impact on scheduling.

Indirect jumps use the same instruction and have type "branch",
so the patch uses "branch" here too.

2019-09-17  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* config/arm/thumb1.md (*thumb1_tablejump): Change type from
	"no_insn" to "branch".

From-SVN: r275806
2019-09-17 15:02:15 +00:00
Richard Sandiford 7dbc2e3b6d Remove name of unused parameter in array-traits.h
2019-09-17  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* array-traits.h (array_traits<T[N]>::size): Remove parameter name.

From-SVN: r275805
2019-09-17 14:27:54 +00:00
Richard Biener 1160be1268 re PR debug/91772 (ICE in add_dwarf_attr, at dwarf2out.c:4412 since r259749)
2019-09-17  Richard Biener  <rguenther@suse.de>

	PR debug/91772
	* dwarf2out.c (dwarf2out_late_global_decl): If early dwarf
	was missing generate locations only once.

From-SVN: r275804
2019-09-17 13:52:20 +00:00
Christophe Lyon 6fbb9dd103 [ARM/FDPIC v6 20/24] [ARM][testsuite] FDPIC: Skip tests using architectures unsupported by FDPIC
Since FDPIC currently supports arm and thumb-2 modes only, these tests
fail because they enforce an architecture version that doesn't match
these restrictions.

This patch introduces new values for the arm_arch effective-target
(v4t_thumb, v5t_thumb, v5te_thumb, v6_thumb, v6k_thumb, v6z_thumb) as
needed, and adds them to the relevant tests.  In addition, it adds
v4t_arm, v5t_arm, v5te_arm, v6_arm, v6k_arm and v6z_arm to avoid
skipping some tests when GCC is configured to generate Thumb code by
default.

It also adds the corresponding non-thumb effective-target to the tests
that were missing it.

The existing v4t, v5t, v5te, v6 v6k and v6z effective-targets now force
-mfloat-abi=softfp since these thumb-1 targets do not support
hard-float anyway.

Finally, the patch removes the special case to detect the presence of
-marm in the flags, since it makes atomic_loaddi tests unsupported:
since the flags in question also include -march, the combination is
supported, while -marm alone is not if GCC is configured to target an
M-profile CPU.

2019-19-17  Christophe Lyon  <christophe.lyon@st.com>

	* lib/target-supports.exp
	(check_effective_target_arm_arch_FUNC_ok): Add v4t_arm, v4t_thumb,
	v5t_arm, v5t_thumb, v5te_arm, v5te_thumb, v6_arm, v6_thumb,
	v6k_arm, v6k_thumb, v6z_arm, v6z_thumb.
	Add -mfloat-abi=softfp to v4t, v5t, v5te, v6, v6k, v6z.
	Remove early exit for -marm.
	* gcc.target/arm/armv6-unaligned-load-ice.c: Add arm_arch
	effective-target.
	* gcc.target/arm/attr-unaligned-load-ice.c: Likewise.
	* gcc.target/arm/ftest-armv4-arm.c: Likewise.
	* gcc.target/arm/ftest-armv4t-arm.c: Likewise.
	* gcc.target/arm/ftest-armv4t-thumb.c: Likewise.
	* gcc.target/arm/ftest-armv5t-arm.c: Likewise.
	* gcc.target/arm/ftest-armv5t-thumb.c: Likewise.
	* gcc.target/arm/ftest-armv5te-arm.c: Likewise.
	* gcc.target/arm/ftest-armv5te-thumb.c: Likewise.
	* gcc.target/arm/ftest-armv6-arm.c: Likewise.
	* gcc.target/arm/ftest-armv6-thumb.c: Likewise.
	* gcc.target/arm/ftest-armv6k-arm.c: Likewise.
	* gcc.target/arm/ftest-armv6k-thumb.c: Likewise.
	* gcc.target/arm/ftest-armv6m-thumb.c: Likewise.
	* gcc.target/arm/ftest-armv6t2-arm.c: Likewise.
	* gcc.target/arm/ftest-armv6t2-thumb.c: Likewise.
	* gcc.target/arm/ftest-armv6z-arm.c: Likewise.
	* gcc.target/arm/ftest-armv6z-thumb.c: Likewise.
	* gcc.target/arm/g2.c: Likewise.
	* gcc.target/arm/macro_defs1.c: Likewise.
	* gcc.target/arm/pr59858.c: Likewise.
	* gcc.target/arm/pr65647-2.c: Likewise.
	* gcc.target/arm/pr79058.c: Likewise.
	* gcc.target/arm/pr83712.c: Likewise.
	* gcc.target/arm/pragma_arch_switch_2.c: Likewise.
	* gcc.target/arm/scd42-1.c: Likewise.
	* gcc.target/arm/scd42-2.c: Likewise.
	* gcc.target/arm/scd42-3.c: Likewise.
	* gcc.c-torture/compile/pr82096.c: Fix arm_arch effective-target.
	* gcc.target/arm/attr_arm-err.c: Likewise.
	* gcc.target/arm/di-longlong64-sync-withldrexd.c: Likewise.

From-SVN: r275803
2019-09-17 14:35:21 +02:00
Feng Xue 351e7c3b5f PR ipa/91089 - Setup predicate for switch default case in IPA
2019-09-17  Feng Xue  <fxue@os.amperecomputing.com>

        PR ipa/91089
        * doc/invoke.texi (ipa-max-switch-predicate-bounds): Document new
        option.
        * params.def (PARAM_IPA_MAX_SWITCH_PREDICATE_BOUNDS): New.
        * ipa-fnsummary.c (set_switch_stmt_execution_predicate): Add predicate
        for switch default case using range analysis information.

2019-09-17  Feng Xue  <fxue@os.amperecomputing.com>

        PR ipa/91089
        * gcc.dg/ipa/pr91089.c: New test.

From-SVN: r275802
2019-09-17 12:30:08 +00:00
Paul Thomas c4ccdc0e63 re PR fortran/91588 (ICE in check_inquiry, at fortran/expr.c:2673)
2019-09-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/91588
	* expr.c (check_inquiry): Remove extended component refs by
	using symbol pointers. If a function argument is an associate
	variable with a constant target, copy the target expression in
	place of the argument expression. Check that the charlen is not
	NULL before using the string length.
	(gfc_check_assign): Remove extraneous space.

2019-09-17  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/91588
	* gfortran.dg/associate_49.f90 : New test.

From-SVN: r275800
2019-09-17 08:30:50 +00:00
Christophe Lyon ecd4d80cb2 [PR91749][arm] FDPIC: Handle -mflip-thumb
2019-09-16  Christophe Lyon  <christophe.lyon@linaro.org>

	PR target/91749
	* config/arm/arm.c (arm_valid_target_attribute_rec): Make sure the
	mode attributed is supported by FDPIC.

From-SVN: r275799
2019-09-17 10:13:11 +02:00
Richard Biener 8054d17a73 re PR tree-optimization/91790 (ICE: verify_ssa failed (error: definition in block 2 follows the use))
2019-09-17  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/91790
	* tree-vect-stmts.c (vectorizable_load): For BB vectorization
	use the correct DR for setting up realignment.

From-SVN: r275798
2019-09-17 08:08:40 +00:00
Claire Dross 994e33d27a [Ada] Add Remove primitive on functional maps
A primitive for removing a mapping from a functional map has been added.

2019-09-17  Claire Dross  <dross@adacore.com>

gcc/ada/

	* libgnat/a-cofuma.ads, libgnat/a-cofuma.adb (Remove): New
	function which returns a copy of the input container without a
	given mapping.

From-SVN: r275797
2019-09-17 08:03:02 +00:00
Yannick Moy e34716b8dd [Ada] Fix rounding of fixed-point arithmetic operation
Fixed-point multiplication, division and conversion may lead to calling
the function Double_Divide in s-arit64 runtime unit. In the special case
where arguments have the special values X = -2**63 and the absolute
value of the product of its other arguments Y*Z = 2**64, the rounded
value should be either -1 or 1, but currently Double_Divide returns a
quotient of 0.

Rounding only applies when Round attribute is called on the arithmetic
operation for a decimal fixed-point result, or the result type is
integer.

This fixes correctly applies rounding away from 0 in that special case.

2019-09-17  Yannick Moy  <moy@adacore.com>

gcc/ada/

	* libgnat/s-arit64.adb (Double_Divide): Correctly handle the
	special case when rounding.

gcc/testsuite/

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

From-SVN: r275796
2019-09-17 08:02:56 +00:00
Javier Miranda 0d4fcc9f62 [Ada] Missing propagation of Has_Predicates in cloned subtypes
The frontend silently skips propagating attributes Has_Predicates and
Predicate function to the internally built cloned subtype. This change
does not affect the functionality of the compiler; it leaves more clean
the decoration of internal entities.

2019-09-17  Javier Miranda  <miranda@adacore.com>

gcc/ada/

	* sem_ch3.adb (Complete_Private_Subtype): Propagate attributes
	Has_Attributes and Predicate_Function to the cloned subtype.

From-SVN: r275795
2019-09-17 08:02:51 +00:00
Eric Botcazou 1e0a3cc4ca [Ada] Fix ineffective -gnatyN for separate compilation units
This fixes a recent regression introduced in the machinery giving style
warnings: the -gnatyN switch no longer cancels an earlier -gnaty switch
for separate compilation units.

Running this command:

  gcc -c slib.adb -gnatyaAbcefhiIklmM25OnprStux -gnatyN

On the following sources:

package Slib is
   procedure I_Am_Short;
end Slib;

with Ada.Text_IO; use Ada.Text_IO;

package body Slib is
   --  have a long line here as well.
   procedure                I_Am_Short is               separate;
end Slib;

separate (Slib)

procedure I_Am_Short is
begin
    Put_Line (".......................................................");
end I_Am_Short;

Should execute silently.

2019-09-17  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* sem.adb (Do_Analyze): Save Style_Check_Max_Line_Length on
	entry and restore it on exit instead of recomputing it.

From-SVN: r275794
2019-09-17 08:02:46 +00:00
Tom Tromey 7afbd9419f [Ada] Update the character type comment in exp_dbug.ads
The character type comment in exp_dbug.ads documented the QU and QW
encodings, but did not document the plain "Qc" encoding, where 'c' is
the character itself.  This patch updates the comment to follow the
implementation.

2019-09-17  Tom Tromey  <tromey@adacore.com>

gcc/ada/

	* exp_dbug.ads: Update character type comment.

From-SVN: r275793
2019-09-17 08:02:41 +00:00
Yannick Moy fd339ba308 [Ada] Minor fixes mostly in comments of runtime arithmetic unit
Multiple comments in functions Double_Divide and Scaled_Divide were
incorrect. Now fixed.

Also change the expression (if Zhi /= 0 then Ylo * Zhi else 0) to the
simpler equivalent (Ylo * Zhi) in Double_Divide.

Also add a comment explaining why the implementation of Algorithm D for
multiple-precision division from the 2nd Edition of The Art of Computer
Programming does not suffer from two bugs discovered on that version.

There is no impact on execution, hence no test.

2019-09-17  Yannick Moy  <moy@adacore.com>

gcc/ada/

	* libgnat/s-arit64.adb (Double_Divide): Simplify needlessly
	complex computation. Fix comments.
	(Scaled_Divide): Fix comments. Explain why implementation does
	not suffer from bugs in Algorithm D from 2nd Edition of TAOCP.

From-SVN: r275792
2019-09-17 08:02:35 +00:00
Yannick Moy d4ba72cbad [Ada] Raise Constraint_Error in overflow case involving rounding
Function Scaled_Divide in s-arith runtime unit computes the combined
multiplication and division of its arguments ((X*Y) / Z). In a very
special case where the quotient computed before rounding is 2**64-1,
then rounding may lead to undesirable wrap-around, leading to a computed
quotient of 0 instead of raising Constraint_Error as expected.

This function is only called in the runtime for arithmetic operations
involving fixed-point types. Rounding is performed only when the target
type is of a decimal fixed-point type, and the attribute 'Round of the
type is used to round the result of the arithmetic operation.

This fix correctly raises Constraint_Error in this special case.

2019-09-17  Yannick Moy  <moy@adacore.com>

gcc/ada/

	* libgnat/s-arit64.adb (Scaled_Divide): Add protection against
	undesirable wrap-around.

gcc/testsuite/

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

From-SVN: r275791
2019-09-17 08:02:30 +00:00
Yannick Moy 7197e2db28 [Ada] Fix possible suppressed overflows in arithmetic run-time
Function Double_Divide computes the division of its parameters
(X / (Y*Z)) in a way that avoids overflows on signed integers, except in
two specific cases, when X = -2**63, abs(Y) = abs(Z) = 1 (leading to an
overflow in -To_Int(Qu)) and when X = -2**63 and Y*Z is large enough
that Qu=0 and so the remainder Ru=2**63 (leading to an overflow in
-To_Int(Ru)), for example with Y = Z = 2**32-1.

This fix avoids the overflow by applying "-" on the unsigned value
before the conversion to signed integer.

The issue cannot manifest as an overflow check failure in our runtime,
as overflow checks are suppressed by using pragma Suppress at the start
of the file. Assuming a machine implements wraparound semantics here,
the result was correct even with the suppressed overflow.

As a result, there can be no test showing the difference.

2019-09-17  Yannick Moy  <moy@adacore.com>

gcc/ada/

	* libgnat/s-arit64.adb (Double_Divide): Fix two possible
	overflows.

From-SVN: r275790
2019-09-17 08:02:25 +00:00
Dmitriy Anisimkov 64989f18c0 [Ada] Force even timestamp in Windows ALI files
Old versions forced even file timestamp in Windows in
GNAT.OS_Lib.GM_Split implementation. We removed this time distortion in
GNAT.OS_Lib.GM_Split a few commits. But gprbuild became unnecessary
recompiling the sources in 50% cases, when the source has odd file
timestamp. This commit is restoring the compatibility between new
gprbuild and old GNAT compilers.

2019-09-17  Dmitriy Anisimkov  <anisimko@adacore.com>

gcc/ada/

	* make_util.ads (On_Windows): Move...
	* osint.ads (On_Windows): There.
	* osint.adb (OS_Time_To_GNAT_Time): If odd incremented on
	Windows before conversion to Time_Stamp_Type.

From-SVN: r275789
2019-09-17 08:02:20 +00:00