[Ada] Prevent In_Check_Node routine from going too far in the parent chain
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 4 Dec 2020 12:00:10 +0000 (13:00 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 17 Dec 2020 10:49:23 +0000 (05:49 -0500)
gcc/ada/

* sem_util.adb (In_Check_Node): Add guard and rename Node to
Par, just like it is done in surrounding routines, e.g.
In_Assertion_Expression_Pragma and In_Generic_Formal_Package.

gcc/ada/sem_util.adb

index 20ec907..759c727 100644 (file)
@@ -13878,14 +13878,20 @@ package body Sem_Util is
    -------------------
 
    function In_Check_Node (N : Node_Id) return Boolean is
-      Node : Node_Id := Parent (N);
+      Par : Node_Id := Parent (N);
    begin
-      while Present (Node) loop
-         if Nkind (Node) in N_Raise_xxx_Error then
+      while Present (Par) loop
+         if Nkind (Par) in N_Raise_xxx_Error then
             return True;
-         end if;
 
-         Node := Parent (Node);
+         --  Prevent the search from going too far
+
+         elsif Is_Body_Or_Package_Declaration (Par) then
+            return False;
+
+         else
+            Par := Parent (Par);
+         end if;
       end loop;
 
       return False;