Named loops (C2y) could not previously be compiled with
-O1 and -ggdb2 or higher because the label preceding
a loop (or switch) could not be found when using such
command lines.

This could be observed by compiling
gcc/gcc/testsuite/gcc.dg/c2y-named-loops-1.c with
the provoking command line (or any minimal example such
as that cited in the bug report).

The fix was simply to ignore the tree nodes inserted
for debugging information.

Base commit is ae4c22ab05501940e345ee799be3aa36ffa7269a

gcc/c/ChangeLog:

        * c-decl.cc (c_get_loop_names): Do not prematurely
        end the search for a label that names a loop or
        switch statement upon encountering a DEBUG_BEGIN_STMT.
        Instead, ignore any instances of DEBUG_BEGIN_STMT.
---
 gcc/c/c-decl.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index c778c7febfa..468b5e90a2f 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -13898,7 +13898,8 @@ c_get_loop_names (tree before_labels, bool switch_p, 
tree *last_p)
              ++ret;
            }
        }
-      else if (TREE_CODE (stmt) != CASE_LABEL_EXPR)
+      else if (TREE_CODE (stmt) != CASE_LABEL_EXPR &&
+              TREE_CODE (stmt) != DEBUG_BEGIN_STMT)
        break;
     }
   if (last)
-- 
2.43.0

Reply via email to