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 79aa2a283a8d3327ff4d6dca77e81d5b1ac3a01e PR c/119317 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/testsuite/ChangeLog: * gcc.dg/c2y-named-loops-8.c: New test. --- gcc/c/c-decl.cc | 3 ++- gcc/testsuite/gcc.dg/c2y-named-loops-8.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/c2y-named-loops-8.c diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 4e200f91107..ad66d7d258b 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -13861,7 +13861,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) diff --git a/gcc/testsuite/gcc.dg/c2y-named-loops-8.c b/gcc/testsuite/gcc.dg/c2y-named-loops-8.c new file mode 100644 index 00000000000..8d69db45f77 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2y-named-loops-8.c @@ -0,0 +1,5 @@ +/* PR c/119317 - Named loops (C2y) did not compile with -O1 and -ggdb2 or higher */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -O1 -ggdb2" } */ + +#include "c2y-named-loops-1.c" -- 2.43.0