]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Don't ICE on computed goto in potential_constant_expression_1 [PR123551]
authorJakub Jelinek <jakub@redhat.com>
Wed, 14 Jan 2026 16:09:13 +0000 (17:09 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 14 Jan 2026 16:09:13 +0000 (17:09 +0100)
r16-968-g5c6364b09a6 has added if (DECL_ARTIFICIAL (*target)) return true;
stmt for GOTO_EXPRs.  This unfortunately ICEs if *target is not a decl,
which is the case for computed gotos.  For those we should always reject
them, so the following patch additionally checks for LABEL_DECL
before testing DECL_ARTIFICIAL on it.

2026-01-14  Jakub Jelinek  <jakub@redhat.com>

PR c++/123551
* constexpr.cc (potential_constant_expression_1) <case GOTO_EXPR>:
Only test DECL_ARTIFICIAL on LABEL_DECLs.

* g++.dg/ext/goto2.C: New test.

gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/ext/goto2.C [new file with mode: 0644]

index 4b362b1caba3309735c12b28008049a2da1aa8a5..54a50c4b6b047c8cd31a7d46dfab8e125808750b 100644 (file)
@@ -12520,7 +12520,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
            *jump_target = *target;
            return true;
          }
-       if (DECL_ARTIFICIAL (*target))
+       if (TREE_CODE (*target) == LABEL_DECL && DECL_ARTIFICIAL (*target))
          /* The user didn't write this goto, this isn't the problem.  */
          return true;
        if (flags & tf_error)
diff --git a/gcc/testsuite/g++.dg/ext/goto2.C b/gcc/testsuite/g++.dg/ext/goto2.C
new file mode 100644 (file)
index 0000000..662c7ef
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/123551
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+void
+foo ()
+{
+  [] () {
+    void *a = &&b;
+    goto *a;
+   b:;
+  };
+}