Commit 184d0451 by Ed Schonberg Committed by Pierre-Marie de Rodat

[Ada] Fix expansion of operations on nonbinary modular types

2018-10-09  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_ch4.adb (Expand_Modular_Op): When expanding an operation
	on nonbinary modular types, convert the opersnds to an integer
	type that is large enough to hold the modulus of the type, which
	may be larger than Integer'Last.

From-SVN: r264973
parent 9e25affd
2018-10-09 Ed Schonberg <schonberg@adacore.com>
* exp_ch4.adb (Expand_Modular_Op): When expanding an operation
on nonbinary modular types, convert the opersnds to an integer
type that is large enough to hold the modulus of the type, which
may be larger than Integer'Last.
2018-10-09 Ed Schonberg <schonberg@adacore.com>
* exp_unst.adb (Unnest_Subprogram): When an uplevel reference
is to an unconstrained formal, the 'Access reference that is
created to initialize the corresponding component of the
......
......@@ -4067,6 +4067,8 @@ package body Exp_Ch4 is
Op_Expr : constant Node_Id := New_Op_Node (Nkind (N), Loc);
Mod_Expr : constant Node_Id := New_Op_Node (N_Op_Mod, Loc);
Target_Type : Entity_Id;
begin
-- Convert nonbinary modular type operands into integer values. Thus
-- we avoid never-ending loops expanding them, and we also ensure
......@@ -4083,11 +4085,21 @@ package body Exp_Ch4 is
Unchecked_Convert_To (Standard_Integer, Op_Expr));
else
-- If the modulus of the type is larger than Integer'Last
-- use a larger type for the operands, to prevent spurious
-- constraint errors on large legal literals of the type.
if Modulus (Etype (N)) > UI_From_Int (Int (Integer'Last)) then
Target_Type := Standard_Long_Integer;
else
Target_Type := Standard_Integer;
end if;
Set_Left_Opnd (Op_Expr,
Unchecked_Convert_To (Standard_Integer,
Unchecked_Convert_To (Target_Type,
New_Copy_Tree (Left_Opnd (N))));
Set_Right_Opnd (Op_Expr,
Unchecked_Convert_To (Standard_Integer,
Unchecked_Convert_To (Target_Type,
New_Copy_Tree (Right_Opnd (N))));
-- Link this node to the tree to analyze it
......
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