[Ada] No_Implicit_Loops restriction and pragma Assert
authorArnaud Charlet <charlet@adacore.com>
Tue, 22 Dec 2020 15:02:29 +0000 (10:02 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 3 May 2021 09:28:21 +0000 (05:28 -0400)
gcc/ada/

* tbuild.adb (Make_Implicit_Loop_Statement): Disable restriction
checking on dead paths.

gcc/ada/tbuild.adb

index 3b33ee7..6febaa7 100644 (file)
@@ -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),