From 56adf813f4e23d95d92385dee9b31e5e0d476abd Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Tue, 22 Dec 2020 10:02:29 -0500 Subject: [PATCH] [Ada] No_Implicit_Loops restriction and pragma Assert gcc/ada/ * tbuild.adb (Make_Implicit_Loop_Statement): Disable restriction checking on dead paths. --- gcc/ada/tbuild.adb | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/gcc/ada/tbuild.adb b/gcc/ada/tbuild.adb index 3b33ee7..6febaa7 100644 --- a/gcc/ada/tbuild.adb +++ b/gcc/ada/tbuild.adb @@ -35,6 +35,7 @@ with Opt; use Opt; with Restrict; use Restrict; with Rident; use Rident; with Sem_Aux; use Sem_Aux; +with Sem_Util; use Sem_Util; with Snames; use Snames; with Stand; use Stand; with Stringt; use Stringt; @@ -348,14 +349,42 @@ package body Tbuild is Has_Created_Identifier : Boolean := False; End_Label : Node_Id := Empty) return Node_Id is - begin - Check_Restriction (No_Implicit_Loops, Node); + P : Node_Id; + Check_Restrictions : Boolean := True; + begin + -- Do not check restrictions if the implicit loop statement is part + -- of a dead branch: False and then ... + -- This will occur in particular as part of the expansion of pragma + -- Assert when assertions are disabled. + + P := Parent (Node); + while Present (P) loop + if Nkind (P) = N_And_Then then + if Nkind (Left_Opnd (P)) = N_Identifier + and then Entity (Left_Opnd (P)) = Standard_False + then + Check_Restrictions := False; + exit; + end if; - if Present (Iteration_Scheme) - and then Nkind (Iteration_Scheme) /= N_Iterator_Specification - and then Present (Condition (Iteration_Scheme)) - then - Check_Restriction (No_Implicit_Conditionals, Node); + -- Prevent the search from going too far + + elsif Is_Body_Or_Package_Declaration (P) then + exit; + end if; + + P := Parent (P); + end loop; + + if Check_Restrictions then + Check_Restriction (No_Implicit_Loops, Node); + + if Present (Iteration_Scheme) + and then Nkind (Iteration_Scheme) /= N_Iterator_Specification + and then Present (Condition (Iteration_Scheme)) + then + Check_Restriction (No_Implicit_Conditionals, Node); + end if; end if; return Make_Loop_Statement (Sloc (Node), -- 2.7.4