Commit 8aceda64 by Arnaud Charlet

exp_ch4.adb (Expand_Composite_Equality): If a component is an unchecked union…

exp_ch4.adb (Expand_Composite_Equality): If a component is an unchecked union with no inferable discriminants...

	* exp_ch4.adb (Expand_Composite_Equality): If a component is an
	unchecked union with no inferable discriminants, return a
	Raise_Program_Error node, rather than inserting it at the point the
	type is frozen.
	(Expand_Record_Equality, Component_Equality): Handle properly the case
	where some subcomponent is an unchecked union whose generated equality
	code raises program error.

From-SVN: r94814
parent 3cf3e5c6
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2004, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -1063,12 +1063,20 @@ package body Exp_Ch4 is ...@@ -1063,12 +1063,20 @@ package body Exp_Ch4 is
Test := Expand_Composite_Equality Test := Expand_Composite_Equality
(Nod, Component_Type (Typ), L, R, Decls); (Nod, Component_Type (Typ), L, R, Decls);
return -- If some (sub)component is an unchecked_union, the whole
Make_Implicit_If_Statement (Nod, -- operation will raise program error.
Condition => Make_Op_Not (Loc, Right_Opnd => Test),
Then_Statements => New_List ( if Nkind (Test) = N_Raise_Program_Error then
Make_Return_Statement (Loc, return Test;
Expression => New_Occurrence_Of (Standard_False, Loc))));
else
return
Make_Implicit_If_Statement (Nod,
Condition => Make_Op_Not (Loc, Right_Opnd => Test),
Then_Statements => New_List (
Make_Return_Statement (Loc,
Expression => New_Occurrence_Of (Standard_False, Loc))));
end if;
end Component_Equality; end Component_Equality;
------------------ ------------------
...@@ -1650,14 +1658,9 @@ package body Exp_Ch4 is ...@@ -1650,14 +1658,9 @@ package body Exp_Ch4 is
-- It is not possible to infer the discriminant since -- It is not possible to infer the discriminant since
-- the subtype is not constrained. -- the subtype is not constrained.
Insert_Action (Nod, return
Make_Raise_Program_Error (Loc, Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction)); Reason => PE_Unchecked_Union_Restriction);
-- Prevent Gigi from generating illegal code, change
-- the equality to a standard False.
return New_Occurrence_Of (Standard_False, Loc);
end if; end if;
-- Rhs of the composite equality -- Rhs of the composite equality
...@@ -1686,11 +1689,9 @@ package body Exp_Ch4 is ...@@ -1686,11 +1689,9 @@ package body Exp_Ch4 is
end if; end if;
else else
Insert_Action (Nod, return
Make_Raise_Program_Error (Loc, Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction)); Reason => PE_Unchecked_Union_Restriction);
return Empty;
end if; end if;
-- Call the TSS equality function with the inferred -- Call the TSS equality function with the inferred
...@@ -7108,6 +7109,7 @@ package body Exp_Ch4 is ...@@ -7108,6 +7109,7 @@ package body Exp_Ch4 is
declare declare
New_Lhs : Node_Id; New_Lhs : Node_Id;
New_Rhs : Node_Id; New_Rhs : Node_Id;
Check : Node_Id;
begin begin
if First_Time then if First_Time then
...@@ -7119,20 +7121,31 @@ package body Exp_Ch4 is ...@@ -7119,20 +7121,31 @@ package body Exp_Ch4 is
New_Rhs := New_Copy_Tree (Rhs); New_Rhs := New_Copy_Tree (Rhs);
end if; end if;
Result := Check :=
Make_And_Then (Loc, Expand_Composite_Equality (Nod, Etype (C),
Left_Opnd => Result, Lhs =>
Right_Opnd => Make_Selected_Component (Loc,
Expand_Composite_Equality (Nod, Etype (C), Prefix => New_Lhs,
Lhs => Selector_Name => New_Reference_To (C, Loc)),
Make_Selected_Component (Loc, Rhs =>
Prefix => New_Lhs, Make_Selected_Component (Loc,
Selector_Name => New_Reference_To (C, Loc)), Prefix => New_Rhs,
Rhs => Selector_Name => New_Reference_To (C, Loc)),
Make_Selected_Component (Loc, Bodies => Bodies);
Prefix => New_Rhs,
Selector_Name => New_Reference_To (C, Loc)), -- If some (sub)component is an unchecked_union, the whole
Bodies => Bodies)); -- operation will raise program error.
if Nkind (Check) = N_Raise_Program_Error then
Result := Check;
Set_Etype (Result, Standard_Boolean);
exit;
else
Result :=
Make_And_Then (Loc,
Left_Opnd => Result,
Right_Opnd => Check);
end if;
end; end;
C := Suitable_Element (Next_Entity (C)); C := Suitable_Element (Next_Entity (C));
......
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