diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2023-02-23 19:13:36 +0100 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-05-23 09:59:06 +0200 |
commit | ad16b816d56a2b49adcc9662275a14bf9e4cf6e9 (patch) | |
tree | c930d4b9b9df1b6718abd691c0dc02a516d5a168 | |
parent | 9826f1e019f6abc5f4960dcfd8f7fcf83dc820dc (diff) | |
download | gcc-ad16b816d56a2b49adcc9662275a14bf9e4cf6e9.zip gcc-ad16b816d56a2b49adcc9662275a14bf9e4cf6e9.tar.gz gcc-ad16b816d56a2b49adcc9662275a14bf9e4cf6e9.tar.bz2 |
ada: Fix resolution of mod operator of System.Storage_Elements
This operator is special because the left operand is of Address type while
the right operand and the result are of Storage_Offset type (but we raise
Constraint_Error if the right operand is not positive) and it needs to be
resolved to the type of the left operand to implement the correct semantics.
gcc/ada/
* exp_ch4.adb (Expand_N_Op_Mod): Adjust the detection of the special
operator of System.Storage_Elements. Do not rewrite it into a rem.
* sem_res.adb (Resolve_Intrinsic_Operator): Use the base type of the
left operand for the special mod operator of System.Storage_Elements
-rw-r--r-- | gcc/ada/exp_ch4.adb | 11 | ||||
-rw-r--r-- | gcc/ada/sem_res.adb | 23 |
2 files changed, 26 insertions, 8 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index c974a9e..c772790 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -9561,9 +9561,10 @@ package body Exp_Ch4 is DDC : constant Boolean := Do_Division_Check (N); Is_Stoele_Mod : constant Boolean := - Is_RTE (First_Subtype (Typ), RE_Storage_Offset) - and then Nkind (Left_Opnd (N)) = N_Unchecked_Type_Conversion - and then Is_RTE (Etype (Expression (Left_Opnd (N))), RE_Address); + Is_RTE (Typ, RE_Address) + and then Nkind (Right_Opnd (N)) = N_Unchecked_Type_Conversion + and then + Is_RTE (Etype (Expression (Right_Opnd (N))), RE_Storage_Offset); -- True if this is the special mod operator of System.Storage_Elements Left : Node_Id; @@ -9633,6 +9634,7 @@ package body Exp_Ch4 is and then ((Llo >= 0 and then Rlo >= 0) or else (Lhi <= 0 and then Rhi <= 0)) + and then not Is_Stoele_Mod then Rewrite (N, Make_Op_Rem (Sloc (N), @@ -9683,7 +9685,8 @@ package body Exp_Ch4 is Make_Raise_Constraint_Error (Loc, Condition => Make_Op_Le (Loc, - Left_Opnd => Duplicate_Subexpr_No_Checks (Right), + Left_Opnd => + Duplicate_Subexpr_No_Checks (Expression (Right)), Right_Opnd => Make_Integer_Literal (Loc, 0)), Reason => CE_Overflow_Check_Failed)); return; diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index a99bed0..f1d9a97 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -9710,10 +9710,19 @@ package body Sem_Res is -------------------------------- procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is - Btyp : constant Entity_Id := Implementation_Base_Type (Typ); - Op : Entity_Id; - Arg1 : Node_Id; - Arg2 : Node_Id; + Is_Stoele_Mod : constant Boolean := + Nkind (N) = N_Op_Mod + and then Is_RTE (First_Subtype (Typ), RE_Storage_Offset) + and then Is_RTE (Etype (Left_Opnd (N)), RE_Address); + -- True if this is the special mod operator of System.Storage_Elements, + -- which needs to be resolved to the type of the left operand in order + -- to implement the correct semantics. + + Btyp : constant Entity_Id := + (if Is_Stoele_Mod + then Implementation_Base_Type (Etype (Left_Opnd (N))) + else Implementation_Base_Type (Typ)); + -- The base type to be used for the operator function Convert_Operand (Opnd : Node_Id) return Node_Id; -- If the operand is a literal, it cannot be the expression in a @@ -9742,6 +9751,12 @@ package body Sem_Res is return Res; end Convert_Operand; + -- Local variables + + Arg1 : Node_Id; + Arg2 : Node_Id; + Op : Entity_Id; + -- Start of processing for Resolve_Intrinsic_Operator begin |