diff options
author | Ed Schonberg <schonberg@adacore.com> | 2018-10-09 15:05:59 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-10-09 15:05:59 +0000 |
commit | 184d0451c491493927816b41dc0b9eebd63601eb (patch) | |
tree | 3ea0782e0c02d213421752d9f21a785be0e78232 /gcc | |
parent | 9e25affdbd810a3a40cc078d2a6415dd4b3baf7b (diff) | |
download | gcc-184d0451c491493927816b41dc0b9eebd63601eb.zip gcc-184d0451c491493927816b41dc0b9eebd63601eb.tar.gz gcc-184d0451c491493927816b41dc0b9eebd63601eb.tar.bz2 |
[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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/ada/exp_ch4.adb | 16 |
2 files changed, 21 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index f95316d..bad8460 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,12 @@ 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 diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index a7aee9f..ace501b 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -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 |