https://gcc.gnu.org/g:640b550425180bdab7bc67edc6a48465f4023888
commit r15-6684-g640b550425180bdab7bc67edc6a48465f4023888 Author: Richard Biener <rguent...@suse.de> Date: Tue Jan 7 15:11:47 2025 +0100 middle-end/118325 - nonlocal goto lowering When nonlocal goto lowering creates an artificial label it fails to adjust its context. PR middle-end/118325 * tree-nested.cc (convert_nl_goto_reference): Assign proper context to generated artificial label. * gcc.dg/pr118325.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/pr118325.c | 16 ++++++++++++++++ gcc/tree-nested.cc | 1 + 2 files changed, 17 insertions(+) diff --git a/gcc/testsuite/gcc.dg/pr118325.c b/gcc/testsuite/gcc.dg/pr118325.c new file mode 100644 index 000000000000..74f92cc2bb6e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr118325.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-std=gnu17 -fchecking" } */ + +void f(void*); + +void z() +{ + void g() + { + __label__ out; + int h(void) { goto out; } + f(h); + out:; + } + f(g); +} diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc index d538c8d2a47d..8d75a2f3310f 100644 --- a/gcc/tree-nested.cc +++ b/gcc/tree-nested.cc @@ -2694,6 +2694,7 @@ convert_nl_goto_reference (gimple_stmt_iterator *gsi, bool *handled_ops_p, { new_label = create_artificial_label (UNKNOWN_LOCATION); DECL_NONLOCAL (new_label) = 1; + DECL_CONTEXT (new_label) = target_context; *slot = new_label; } else