This removes the left-overs of an expansion done in Expand_Call_Helper
in order to pass the correct accessibility level to the callee when
the actual is an if-expression of an access type. The expansion uses
a dummy temporary to analyze the outermost Expression_With_Actions it
makes and removes its declaration afterward but, if the temporary is
of a tagged type, there is more to be removed after the declaration.
This also changes the type of the minimum accessibility level object
created by Analyze_Subprogram_Body_Helper to Natural and enhances
Determine_Range to deal with the Min and Max attributes that are used
to initialize the object, the end goal being to remove an useless
range check generated for the accessibility level itself.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* checks.adb (Determine_Range): Deal with Min and Max attributes.
* exp_ch6.adb (Expand_Call_Helper): When generating code to pass
the accessibility level to the caller in the case of an actual
which is an if-expression, also remove the nodes created after
the declaration of the dummy temporary.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Use Natural as
the type of the minimum accessibility level object.
diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -5119,6 +5119,27 @@ package body Checks is
when N_Attribute_Reference =>
case Get_Attribute_Id (Attribute_Name (N)) is
+ -- For Min/Max attributes, we can refine the range using the
+ -- possible range of values of the attribute expressions.
+
+ when Attribute_Min
+ | Attribute_Max
+ =>
+ Determine_Range
+ (First (Expressions (N)),
+ OK1, Lo_Left, Hi_Left, Assume_Valid);
+
+ if OK1 then
+ Determine_Range
+ (Next (First (Expressions (N))),
+ OK1, Lo_Right, Hi_Right, Assume_Valid);
+ end if;
+
+ if OK1 then
+ Lor := UI_Min (Lo_Left, Lo_Right);
+ Hir := UI_Max (Hi_Left, Hi_Right);
+ end if;
+
-- For Pos/Val attributes, we can refine the range using the
-- possible range of values of the attribute expression.
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -3927,6 +3927,8 @@ package body Exp_Ch6 is
then
declare
Decl : Node_Id;
+ pragma Warnings (Off, Decl);
+ -- Suppress warning for the final removal loop
Lvl : Entity_Id;
Res : Entity_Id;
Temp : Node_Id;
@@ -4045,8 +4047,7 @@ package body Exp_Ch6 is
-- expansion if we are dealing with a function
-- call.
- if Nkind (Call_Node) =
- N_Procedure_Call_Statement
+ if Nkind (Call_Node) = N_Procedure_Call_Statement
then
-- Generate:
-- Lvl : Natural;
@@ -4109,7 +4110,13 @@ package body Exp_Ch6 is
Set_Expression (Call_Node, Relocate_Node (Temp));
Call_Node := Expression (Call_Node);
- Remove (Next (Decl));
+
+ -- Remove the declaration of the dummy and the
+ -- subsequent actions its analysis has created.
+
+ while Present (Remove_Next (Decl)) loop
+ null;
+ end loop;
end if;
-- Decorate the conditional expression with
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -4684,7 +4684,7 @@ package body Sem_Ch6 is
then
-- Generate the minimum accessibility level object
- -- A60b : integer := integer'min(2, paramL);
+ -- A60b : natural := natural'min(1, paramL);
declare
Loc : constant Source_Ptr := Sloc (Body_Nod);
@@ -4694,11 +4694,11 @@ package body Sem_Ch6 is
Make_Temporary
(Loc, 'A', Extra_Accessibility (Form)),
Object_Definition => New_Occurrence_Of
- (Standard_Integer, Loc),
+ (Standard_Natural, Loc),
Expression =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of
- (Standard_Integer, Loc),
+ (Standard_Natural, Loc),
Attribute_Name => Name_Min,
Expressions => New_List (
Make_Integer_Literal (Loc,