diff options
author | Arnaud Charlet <charlet@adacore.com> | 2020-07-13 08:14:20 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-10-20 03:21:31 -0400 |
commit | bc60bb5eb9b18315b1af7ffa408969690720f8b1 (patch) | |
tree | ae8e307920d592949bd418df1f0f85427333a08b /gcc | |
parent | f3f1debe1b79b736cb1a29a11c06f63cee92ad06 (diff) | |
download | gcc-bc60bb5eb9b18315b1af7ffa408969690720f8b1.zip gcc-bc60bb5eb9b18315b1af7ffa408969690720f8b1.tar.gz gcc-bc60bb5eb9b18315b1af7ffa408969690720f8b1.tar.bz2 |
[Ada] Remove extra validity check in case statement
gcc/ada/
* exp_ch5.adb (Expand_N_Case_Statement): Do not generate
validity check when possible.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/exp_ch5.adb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index 9a31988..5576645 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -3115,7 +3115,35 @@ package body Exp_Ch5 is if Validity_Check_Default and then not Predicates_Ignored (Etype (Expr)) then - Ensure_Valid (Expr); + -- 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); + end if; + end; end if; -- If there is only a single alternative, just replace it with the |