[Ada] Remove extra validity check in case statement
gcc/ada/ * exp_ch5.adb (Expand_N_Case_Statement): Do not generate validity check when possible.
This commit is contained in:
parent
f3f1debe1b
commit
bc60bb5eb9
@ -3115,8 +3115,36 @@ package body Exp_Ch5 is
|
|||||||
if Validity_Check_Default
|
if Validity_Check_Default
|
||||||
and then not Predicates_Ignored (Etype (Expr))
|
and then not Predicates_Ignored (Etype (Expr))
|
||||||
then
|
then
|
||||||
|
-- Recognize the simple case where Expr is an object reference
|
||||||
|
-- and the case statement is directly preceded by an
|
||||||
|
-- "if Obj'Valid then": in this case, do not emit another validity
|
||||||
|
-- check.
|
||||||
|
|
||||||
|
declare
|
||||||
|
Check_Validity : Boolean := True;
|
||||||
|
Attr : Node_Id;
|
||||||
|
begin
|
||||||
|
if Nkind (Expr) = N_Identifier
|
||||||
|
and then Nkind (Parent (N)) = N_If_Statement
|
||||||
|
and then Nkind (Original_Node (Condition (Parent (N))))
|
||||||
|
= N_Attribute_Reference
|
||||||
|
and then No (Prev (N))
|
||||||
|
then
|
||||||
|
Attr := Original_Node (Condition (Parent (N)));
|
||||||
|
|
||||||
|
if Attribute_Name (Attr) = Name_Valid
|
||||||
|
and then Nkind (Prefix (Attr)) = N_Identifier
|
||||||
|
and then Entity (Prefix (Attr)) = Entity (Expr)
|
||||||
|
then
|
||||||
|
Check_Validity := False;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if Check_Validity then
|
||||||
Ensure_Valid (Expr);
|
Ensure_Valid (Expr);
|
||||||
end if;
|
end if;
|
||||||
|
end;
|
||||||
|
end if;
|
||||||
|
|
||||||
-- If there is only a single alternative, just replace it with the
|
-- If there is only a single alternative, just replace it with the
|
||||||
-- sequence of statements since obviously that is what is going to
|
-- sequence of statements since obviously that is what is going to
|
||||||
|
Loading…
Reference in New Issue
Block a user