[gcc r16-6777] c++: Don't ICE on computed goto in potential_constant_expression_1 [PR123551]
Jakub Jelinek
jakub@gcc.gnu.org
Wed Jan 14 16:09:56 GMT 2026
https://gcc.gnu.org/g:e4c2d1952a6f0d00430f8cbed796524650211cc3
commit r16-6777-ge4c2d1952a6f0d00430f8cbed796524650211cc3
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Jan 14 17:09:13 2026 +0100
c++: Don't ICE on computed goto in potential_constant_expression_1 [PR123551]
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.
Diff:
---
gcc/cp/constexpr.cc | 2 +-
gcc/testsuite/g++.dg/ext/goto2.C | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 4b362b1caba3..54a50c4b6b04 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -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
index 000000000000..662c7efad038
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/goto2.C
@@ -0,0 +1,13 @@
+// PR c++/123551
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+void
+foo ()
+{
+ [] () {
+ void *a = &&b;
+ goto *a;
+ b:;
+ };
+}
More information about the Gcc-cvs
mailing list