Commit 7f4b58c2 by Hristian Kirtchev Committed by Pierre-Marie de Rodat

[Ada] Spurious Storage_Error on imported array

This patch moves the check which verifies that a large modular array is created
from expansion to freezing in order to take interfacing pragmas in account. The
check is no longer performed on imported objects because no object is created
in that case.

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

gcc/ada/

	* exp_ch3.adb (Check_Large_Modular_Array): Moved to Freeze.
	(Expand_N_Object_Declaration): Do not check for a large modular array
	here.
	* freeze.adb (Check_Large_Modular_Array): Moved from Exp_Ch3.
	(Freeze_Object_Declaration): Code cleanup. Check for a large modular
	array.
	* sem_ch3.adb: Minor reformatting.

gcc/testsuite/

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

From-SVN: r260597
parent ffdd5248
2018-05-23 Hristian Kirtchev <kirtchev@adacore.com>
* exp_ch3.adb (Check_Large_Modular_Array): Moved to Freeze.
(Expand_N_Object_Declaration): Do not check for a large modular array
here.
* freeze.adb (Check_Large_Modular_Array): Moved from Exp_Ch3.
(Freeze_Object_Declaration): Code cleanup. Check for a large modular
array.
* sem_ch3.adb: Minor reformatting.
2018-05-23 Ed Schonberg <schonberg@adacore.com>
* einfo.ads: New attribute on types: Predicated_Parent, to simplify the
......
......@@ -5606,13 +5606,6 @@ package body Exp_Ch3 is
-- value, it may be possible to build an equivalent aggregate instead,
-- and prevent an actual call to the initialization procedure.
procedure Check_Large_Modular_Array;
-- Check that the size of the array can be computed without overflow,
-- and generate a Storage_Error otherwise. This is only relevant for
-- array types whose index in a (mod 2**64) type, where wrap-around
-- arithmetic might yield a meaningless value for the length of the
-- array, or its corresponding attribute.
procedure Count_Default_Sized_Task_Stacks
(Typ : Entity_Id;
Pri_Stacks : out Int;
......@@ -5759,61 +5752,6 @@ package body Exp_Ch3 is
end if;
end Build_Equivalent_Aggregate;
-------------------------------
-- Check_Large_Modular_Array --
-------------------------------
procedure Check_Large_Modular_Array is
Index_Typ : Entity_Id;
begin
if Is_Array_Type (Typ)
and then Is_Modular_Integer_Type (Etype (First_Index (Typ)))
then
-- To prevent arithmetic overflow with large values, we raise
-- Storage_Error under the following guard:
-- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
-- This takes care of the boundary case, but it is preferable to
-- use a smaller limit, because even on 64-bit architectures an
-- array of more than 2 ** 30 bytes is likely to raise
-- Storage_Error.
Index_Typ := Etype (First_Index (Typ));
if RM_Size (Index_Typ) = RM_Size (Standard_Long_Long_Integer) then
Insert_Action (N,
Make_Raise_Storage_Error (Loc,
Condition =>
Make_Op_Ge (Loc,
Left_Opnd =>
Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Op_Divide (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Last),
Right_Opnd =>
Make_Integer_Literal (Loc, Uint_2)),
Right_Opnd =>
Make_Op_Divide (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_First),
Right_Opnd =>
Make_Integer_Literal (Loc, Uint_2))),
Right_Opnd =>
Make_Integer_Literal (Loc, (Uint_2 ** 30))),
Reason => SE_Object_Too_Large));
end if;
end if;
end Check_Large_Modular_Array;
-------------------------------------
-- Count_Default_Sized_Task_Stacks --
-------------------------------------
......@@ -6434,8 +6372,6 @@ package body Exp_Ch3 is
Build_Master_Entity (Def_Id);
end if;
Check_Large_Modular_Array;
-- If No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations
-- restrictions are active then default-sized secondary stacks are
-- generated by the binder and allocated by SS_Init. To provide the
......
......@@ -21676,7 +21676,8 @@ package body Sem_Ch3 is
then
Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix);
-- ... but more comonly by a discriminated record type.
-- ... but more commonly is completed by a discriminated record
-- type.
else
Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
......
2018-05-23 Hristian Kirtchev <kirtchev@adacore.com>
* gnat.dg/import2.adb: New testcase.
2018-05-23 Ed Schonberg <schonberg@adacore.com>
* gnat.dg/discr51.adb: New testcase.
......
-- { dg-do run }
procedure Import2 is
type Index_Typ is mod 2**64;
type Mod_Array is array (Index_Typ) of Integer;
Obj : Mod_Array;
pragma Import (Ada, Obj);
begin
null;
end Import2;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment