]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/118325 - nonlocal goto lowering
authorRichard Biener <rguenther@suse.de>
Tue, 7 Jan 2025 14:11:47 +0000 (15:11 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 8 Jan 2025 07:21:50 +0000 (08:21 +0100)
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.

gcc/testsuite/gcc.dg/pr118325.c [new file with mode: 0644]
gcc/tree-nested.cc

diff --git a/gcc/testsuite/gcc.dg/pr118325.c b/gcc/testsuite/gcc.dg/pr118325.c
new file mode 100644 (file)
index 0000000..74f92cc
--- /dev/null
@@ -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);
+}
index d538c8d2a47d5913c26273216313280c521122bf..8d75a2f3310f643a83b30f4fa5cca2e22272389b 100644 (file)
@@ -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