OSDN Git Service

PR middle-end/46844
[pf3gnuchains/gcc-fork.git] / gcc / ada / par-labl.adb
index 2ce8d6f..8520292 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2007, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -177,10 +177,10 @@ procedure Labl is
 
       procedure No_Header (N : Elmt_Id);
       --  The label N is known not to be a loop header. Scan forward and
-      --  remove all subsequent goto's that may have this node as a target.
+      --  remove all subsequent gotos that may have this node as a target.
 
       procedure Process_Goto (N : Elmt_Id);
-      --  N is a forward jump. Scan forward and remove all subsequent goto's
+      --  N is a forward jump. Scan forward and remove all subsequent gotos
       --  that may have the same target, to preclude spurious loops.
 
       procedure Rewrite_As_Loop
@@ -375,13 +375,19 @@ procedure Labl is
               and then Matches (Node (N), Node (S1))
             then
                if not Found then
-                  if Parent (Node (N)) = Parent (Node (S1)) then
+
+                  --  If the label and the goto are both in the same statement
+                  --  list, then we've found a loop. Note that labels and goto
+                  --  statements are always part of some list, so In_Same_List
+                  --  always makes sense.
+
+                  if In_Same_List (Node (N), Node (S1)) then
                      Source := S1;
                      Found  := True;
 
-                  else
-                     --  The goto is within some nested structure
+                  --  The goto is within some nested structure
 
+                  else
                      No_Header (N);
                      return;
                   end if;