When nonlocal goto lowering creates an artificial label it fails to adjust its context.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress (I doubt good test coverage is present for non-local gotos) OK when testing succeeds? Thanks, Richard. PR middle-end/118325 * tree-nested.cc (convert_nl_goto_reference): Assign proper context to generated artificial label. * gcc.dg/pr118325.c: New testcase. --- gcc/testsuite/gcc.dg/pr118325.c | 16 ++++++++++++++++ gcc/tree-nested.cc | 1 + 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr118325.c diff --git a/gcc/testsuite/gcc.dg/pr118325.c b/gcc/testsuite/gcc.dg/pr118325.c new file mode 100644 index 00000000000..74f92cc2bb6 --- /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 d538c8d2a47..8d75a2f3310 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 -- 2.43.0