Commit 076bbec1 by Ed Schonberg Committed by Pierre-Marie de Rodat

[Ada] Problem with boundary case of XOR operation and unnesting

The XOR operation applied to a boolean array whose component type has
the range True .. True raises constraint error. Previous to this patch,
the expansion of the operation could lead to uplevel references that
were not handled properly when unnesting is in effect.

2018-11-14  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_util.ads, exp_util.adb: Change the profile of
	Silly_Boolean_Array_Xor_Test, adding a formal that can be a copy
	of the right opersnd. This prevents unnesting anomalies when
	that operand contains uplevel references.
	* exp_ch4.adb (Expand_Boolean_Operation): Use this new profile.
	* exp_pakd.adb (Expand_Packed_Boolean_Operator): Ditto.

From-SVN: r266137
parent 9989a439
2018-11-14 Ed Schonberg <schonberg@adacore.com>
* exp_util.ads, exp_util.adb: Change the profile of
Silly_Boolean_Array_Xor_Test, adding a formal that can be a copy
of the right opersnd. This prevents unnesting anomalies when
that operand contains uplevel references.
* exp_ch4.adb (Expand_Boolean_Operation): Use this new profile.
* exp_pakd.adb (Expand_Packed_Boolean_Operator): Ditto.
2018-11-14 Patrick Bernardi <bernardi@adacore.com> 2018-11-14 Patrick Bernardi <bernardi@adacore.com>
* libgnarl/a-intnam__linux.ads: Add SIGSYS. * libgnarl/a-intnam__linux.ads: Add SIGSYS.
......
...@@ -2031,7 +2031,7 @@ package body Exp_Ch4 is ...@@ -2031,7 +2031,7 @@ package body Exp_Ch4 is
declare declare
Loc : constant Source_Ptr := Sloc (N); Loc : constant Source_Ptr := Sloc (N);
L : constant Node_Id := Relocate_Node (Left_Opnd (N)); L : constant Node_Id := Relocate_Node (Left_Opnd (N));
R : constant Node_Id := Relocate_Node (Right_Opnd (N)); R : Node_Id := Relocate_Node (Right_Opnd (N));
Func_Body : Node_Id; Func_Body : Node_Id;
Func_Name : Entity_Id; Func_Name : Entity_Id;
...@@ -2043,7 +2043,8 @@ package body Exp_Ch4 is ...@@ -2043,7 +2043,8 @@ package body Exp_Ch4 is
Apply_Length_Check (R, Etype (L)); Apply_Length_Check (R, Etype (L));
if Nkind (N) = N_Op_Xor then if Nkind (N) = N_Op_Xor then
Silly_Boolean_Array_Xor_Test (N, Etype (L)); R := Duplicate_Subexpr (R);
Silly_Boolean_Array_Xor_Test (N, R, Etype (L));
end if; end if;
if Nkind (Parent (N)) = N_Assignment_Statement if Nkind (Parent (N)) = N_Assignment_Statement
......
...@@ -1506,7 +1506,7 @@ package body Exp_Pakd is ...@@ -1506,7 +1506,7 @@ package body Exp_Pakd is
Loc : constant Source_Ptr := Sloc (N); Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N); Typ : constant Entity_Id := Etype (N);
L : constant Node_Id := Relocate_Node (Left_Opnd (N)); L : constant Node_Id := Relocate_Node (Left_Opnd (N));
R : constant Node_Id := Relocate_Node (Right_Opnd (N)); R : Node_Id := Relocate_Node (Right_Opnd (N));
Ltyp : Entity_Id; Ltyp : Entity_Id;
Rtyp : Entity_Id; Rtyp : Entity_Id;
...@@ -1528,7 +1528,8 @@ package body Exp_Pakd is ...@@ -1528,7 +1528,8 @@ package body Exp_Pakd is
-- True .. True where an exception must be raised. -- True .. True where an exception must be raised.
if Nkind (N) = N_Op_Xor then if Nkind (N) = N_Op_Xor then
Silly_Boolean_Array_Xor_Test (N, Rtyp); R := Duplicate_Subexpr (R);
Silly_Boolean_Array_Xor_Test (N, R, Rtyp);
end if; end if;
-- Now that that silliness is taken care of, get packed array type -- Now that that silliness is taken care of, get packed array type
......
...@@ -7062,7 +7062,6 @@ package body Exp_Util is ...@@ -7062,7 +7062,6 @@ package body Exp_Util is
| N_Procedure_Instantiation | N_Procedure_Instantiation
| N_Protected_Body | N_Protected_Body
| N_Protected_Body_Stub | N_Protected_Body_Stub
| N_Protected_Type_Declaration
| N_Single_Task_Declaration | N_Single_Task_Declaration
| N_Subprogram_Body | N_Subprogram_Body
| N_Subprogram_Body_Stub | N_Subprogram_Body_Stub
...@@ -7071,7 +7070,6 @@ package body Exp_Util is ...@@ -7071,7 +7070,6 @@ package body Exp_Util is
| N_Subtype_Declaration | N_Subtype_Declaration
| N_Task_Body | N_Task_Body
| N_Task_Body_Stub | N_Task_Body_Stub
| N_Task_Type_Declaration
-- Use clauses can appear in lists of declarations -- Use clauses can appear in lists of declarations
...@@ -7135,6 +7133,21 @@ package body Exp_Util is ...@@ -7135,6 +7133,21 @@ package body Exp_Util is
return; return;
end if; end if;
-- the expansion of Task and protected type declarations can
-- create declarations for temporaries which, like other actions
-- are inserted and analyzed before the current declaraation.
-- However, the current scope is the synchronized type, and
-- for unnesting it is critical that the proper scope for these
-- generated entities be the enclosing one.
when N_Task_Type_Declaration
| N_Protected_Type_Declaration =>
Push_Scope (Scope (Current_Scope));
Insert_List_Before_And_Analyze (P, Ins_Actions);
Pop_Scope;
return;
-- A special case, N_Raise_xxx_Error can act either as a statement -- A special case, N_Raise_xxx_Error can act either as a statement
-- or a subexpression. We tell the difference by looking at the -- or a subexpression. We tell the difference by looking at the
-- Etype. It is set to Standard_Void_Type in the statement case. -- Etype. It is set to Standard_Void_Type in the statement case.
...@@ -13400,7 +13413,8 @@ package body Exp_Util is ...@@ -13400,7 +13413,8 @@ package body Exp_Util is
-- required for the case of False .. False, since False xor False = False. -- required for the case of False .. False, since False xor False = False.
-- See also Silly_Boolean_Array_Not_Test -- See also Silly_Boolean_Array_Not_Test
procedure Silly_Boolean_Array_Xor_Test (N : Node_Id; T : Entity_Id) is procedure Silly_Boolean_Array_Xor_Test
(N : Node_Id; R : Node_Id; T : Entity_Id) is
Loc : constant Source_Ptr := Sloc (N); Loc : constant Source_Ptr := Sloc (N);
CT : constant Entity_Id := Component_Type (T); CT : constant Entity_Id := Component_Type (T);
...@@ -13435,7 +13449,7 @@ package body Exp_Util is ...@@ -13435,7 +13449,7 @@ package body Exp_Util is
Prefix => New_Occurrence_Of (CT, Loc), Prefix => New_Occurrence_Of (CT, Loc),
Attribute_Name => Name_Last))), Attribute_Name => Name_Last))),
Right_Opnd => Make_Non_Empty_Check (Loc, Right_Opnd (N))), Right_Opnd => Make_Non_Empty_Check (Loc, R)),
Reason => CE_Range_Check_Failed)); Reason => CE_Range_Check_Failed));
end Silly_Boolean_Array_Xor_Test; end Silly_Boolean_Array_Xor_Test;
......
...@@ -1140,11 +1140,14 @@ package Exp_Util is ...@@ -1140,11 +1140,14 @@ package Exp_Util is
-- the boolean array is False..False or True..True, where it is required -- the boolean array is False..False or True..True, where it is required
-- that a Constraint_Error exception be raised (RM 4.5.6(6)). -- that a Constraint_Error exception be raised (RM 4.5.6(6)).
procedure Silly_Boolean_Array_Xor_Test (N : Node_Id; T : Entity_Id); procedure Silly_Boolean_Array_Xor_Test
-- N is the node for a boolean array XOR operation, and T is the type of (N : Node_Id; R : Node_Id; T : Entity_Id);
-- the array. This routine deals with the silly case where the subtype of -- N is the node for a boolean array XOR operation, T is the type of the
-- the boolean array is True..True, where a raise of a Constraint_Error -- array, and R is a copy of the right operand of N, required to prevent
-- exception is required (RM 4.5.6(6)). -- scope anomalies when unnesting is in effect. This routine deals with
-- the admitedly silly case where the subtype of the boolean array is
-- True..True, where a raise of a Constraint_Error exception is required
-- (RM 4.5.6(6)) and ACATS-tested.
function Target_Has_Fixed_Ops function Target_Has_Fixed_Ops
(Left_Typ : Entity_Id; (Left_Typ : Entity_Id;
......
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