From 7dbd3de9e50f4c72619f1ab5dfcb77cbd8269a6d Mon Sep 17 00:00:00 2001 From: Robert Dewar Date: Mon, 20 Jan 2014 15:49:09 +0000 Subject: [PATCH] gnat_rm.texi (Allow_Integer_Address): Remove note about not allowed if address is non-private, no longer true. 2014-01-20 Robert Dewar * gnat_rm.texi (Allow_Integer_Address): Remove note about not allowed if address is non-private, no longer true. * sem_prag.adb (Analyze_Pragma, case Allow_Integer_Address): Remove check for address being private, causes difficulty when pragma used in gnat.adc file and is not needed, since we guard this in Address_Integer_Convert_OK. * exp_ch7.adb: Minor reformatting. * sem_ch4.adb: Handle operator operands in Allow_Integer_Address mode. 2014-01-20 Robert Dewar * checks.adb (Apply_Range_Check): Remove gnatprove special casing of exponentiation. * sem_res.adb (Resolve_Op_Expon): Apply range check to right operand for integer case to check range against Natural. From-SVN: r206833 --- gcc/ada/ChangeLog | 18 ++++++++++++++++++ gcc/ada/checks.adb | 13 ------------- gcc/ada/exp_ch7.adb | 2 +- gcc/ada/gnat_rm.texi | 12 +++--------- gcc/ada/sem_ch4.adb | 21 +++++++++++++++++++-- gcc/ada/sem_prag.adb | 6 ------ gcc/ada/sem_res.adb | 6 ++++++ 7 files changed, 47 insertions(+), 31 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 93c1d9f..395cc96 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,23 @@ 2014-01-20 Robert Dewar + * gnat_rm.texi (Allow_Integer_Address): Remove note about not + allowed if address is non-private, no longer true. + * sem_prag.adb (Analyze_Pragma, case Allow_Integer_Address): + Remove check for address being private, causes difficulty when + pragma used in gnat.adc file and is not needed, since we guard + this in Address_Integer_Convert_OK. + * exp_ch7.adb: Minor reformatting. + * sem_ch4.adb: Handle operator operands in Allow_Integer_Address mode. + +2014-01-20 Robert Dewar + + * checks.adb (Apply_Range_Check): Remove gnatprove special + casing of exponentiation. + * sem_res.adb (Resolve_Op_Expon): Apply range check to right + operand for integer case to check range against Natural. + +2014-01-20 Robert Dewar + * s-tataat.adb: Minor reformatting. 2014-01-20 Robert Dewar diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index 8b8fdd8..1e4cff8 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -2797,19 +2797,6 @@ package body Checks is return; end if; - -- Ensure that the exponent is a natural. The flag is set only in formal - -- verification mode as the expander takes care of this check and there - -- is no expansion phase in GNATprove_Mode. - - -- Doesn't seem right to do this unconditionally, we should check the - -- range of the exponent operand. If we do that, it seems like we should - -- then set the flag unconditionally and have the expander check the - -- flag to see whether to generate a check ??? - - if GNATprove_Mode and then Nkind (Expr) = N_Op_Expon then - Set_Do_Range_Check (Right_Opnd (Expr)); - end if; - Is_Unconstrained_Subscr_Ref := Is_Subscr_Ref and then not Is_Constrained (Arr_Typ); diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index 42d499b..9739cad 100644 --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -7987,7 +7987,7 @@ package body Exp_Ch7 is -- signalling the decision outcome occurs before the cleanup actions. if Opt.Suppress_Control_Flow_Optimizations - and then Is_Boolean_Type (Typ) + and then Is_Boolean_Type (Typ) then Expr := Make_If_Expression (Loc, diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi index 53286d8..64bfce1 100644 --- a/gcc/ada/gnat_rm.texi +++ b/gcc/ada/gnat_rm.texi @@ -1231,9 +1231,9 @@ pragma Allow_Integer_Address; @end smallexample @noindent -This configuration pragma is allowed only -if type @code{System.Address} is a private type, -which is true in most versions of GNAT. which means that integer values, +In almost all versions of GNAT, @code{System.Address} is a private +type in accordance with the implementation advice in the RM. This +means that integer values, in particular integer literals, are not allowed as address values. If the configuration pragma @code{Allow_Integer_Address} is given, then integer expressions may @@ -1263,12 +1263,6 @@ package AddrAsInt is end AddrAsInt; @end smallexample -@noindent -Note that these automatic conversions do not apply to expressions used -as subprogram arguments, because in general overloading can take place, -so that the required type is not fixed by the context. If necessary -adjust the type of the subprogram argument, e.g. by adding a conversion. - @node Pragma Annotate @unnumberedsec Pragma Annotate @findex Annotate diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index daf8afe..bf4e317 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -6367,16 +6367,33 @@ package body Sem_Ch4 is N_Op_Rem, N_Op_Subtract) then + -- If Allow_Integer_Address is active, check whether the + -- operation becomes legal after converting an operand. + if Is_Numeric_Type (Etype (L)) and then not Is_Numeric_Type (Etype (R)) then - Resolve (R, Etype (L)); + if Address_Integer_Convert_OK (Etype (R), Etype (L)) then + Rewrite (R, + Unchecked_Convert_To (Etype (L), Relocate_Node (R))); + Analyze_Arithmetic_Op (N); + + else + Resolve (R, Etype (L)); + end if; return; elsif Is_Numeric_Type (Etype (R)) and then not Is_Numeric_Type (Etype (L)) then - Resolve (L, Etype (R)); + if Address_Integer_Convert_OK (Etype (L), Etype (R)) then + Rewrite (L, + Unchecked_Convert_To (Etype (R), Relocate_Node (L))); + Analyze_Arithmetic_Op (N); + + else + Resolve (L, Etype (R)); + end if; return; end if; diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index ad5e004..7520856 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -9853,12 +9853,6 @@ package body Sem_Prag is when Pragma_Allow_Integer_Address => GNAT_Pragma; Check_Arg_Count (0); - - if not Is_Private_Type (RTE (RE_Address)) then - Error_Pragma - ("pragma% allowed only if Address is a private type"); - end if; - Opt.Allow_Integer_Address := True; -------------- diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 89fbb75..e9d62a4 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -8393,6 +8393,12 @@ package body Sem_Res is Resolve (Left_Opnd (N), B_Typ); Resolve (Right_Opnd (N), Standard_Integer); + -- For integer types, right argument must be in Natural range + + if Is_Integer_Type (Typ) then + Apply_Scalar_Range_Check (Right_Opnd (N), Standard_Natural); + end if; + Check_Unset_Reference (Left_Opnd (N)); Check_Unset_Reference (Right_Opnd (N)); -- 2.7.4