aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2024-06-26 17:55:21 -0400
committerMarek Polacek <polacek@redhat.com>2024-07-01 18:16:48 -0400
commitc90e785bb6fde02cc009f296332a1469fcc1261a (patch)
tree2418b849790a5688cf897dc73578f03f256f0ac1
parentcb39f7df8d1c16cc2763952a9cc0c828ba88b4d7 (diff)
downloadgcc-c90e785bb6fde02cc009f296332a1469fcc1261a.zip
gcc-c90e785bb6fde02cc009f296332a1469fcc1261a.tar.gz
gcc-c90e785bb6fde02cc009f296332a1469fcc1261a.tar.bz2
c++: ICE with computed gotos [PR115469]
This is a low-prio crash on invalid code where we ICE on a VAR_DECL with erroneous type. I thought I'd try to avoid putting such decls into ->names and ->names_in_scope but that sounds riskier than the following cleanup. PR c++/115469 gcc/cp/ChangeLog: * decl.cc (automatic_var_with_nontrivial_dtor_p): New. (poplevel_named_label_1): Use it. (check_goto_1): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/label17.C: New test.
-rw-r--r--gcc/cp/decl.cc20
-rw-r--r--gcc/testsuite/g++.dg/ext/label17.C18
2 files changed, 34 insertions, 4 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 03deb14..c7457fae 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -514,6 +514,20 @@ level_for_consteval_if (cp_binding_level *b)
&& IF_STMT_CONSTEVAL_P (b->this_entity));
}
+/* True if T is a non-static VAR_DECL that has a non-trivial destructor.
+ See [stmt.dcl]/2. */
+
+static bool
+automatic_var_with_nontrivial_dtor_p (const_tree t)
+{
+ if (error_operand_p (t))
+ return false;
+
+ return (VAR_P (t)
+ && decl_storage_duration (CONST_CAST_TREE (t)) == dk_auto
+ && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
+}
+
/* Update data for defined and undefined labels when leaving a scope. */
int
@@ -575,8 +589,7 @@ poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
if (bl->kind == sk_catch)
vec_safe_push (cg, get_identifier ("catch"));
for (tree d = use->names_in_scope; d; d = DECL_CHAIN (d))
- if (TREE_CODE (d) == VAR_DECL && !TREE_STATIC (d)
- && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (d)))
+ if (automatic_var_with_nontrivial_dtor_p (d))
vec_safe_push (cg, d);
}
@@ -4003,8 +4016,7 @@ check_goto_1 (named_label_entry *ent, bool computed)
tree end = b == level ? names : NULL_TREE;
for (tree d = b->names; d != end; d = DECL_CHAIN (d))
{
- if (TREE_CODE (d) == VAR_DECL && !TREE_STATIC (d)
- && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (d)))
+ if (automatic_var_with_nontrivial_dtor_p (d))
{
if (!identified)
{
diff --git a/gcc/testsuite/g++.dg/ext/label17.C b/gcc/testsuite/g++.dg/ext/label17.C
new file mode 100644
index 0000000..076ef1f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/label17.C
@@ -0,0 +1,18 @@
+// PR c++/115469
+// { dg-do compile { target indirect_jumps } }
+// { dg-options "" }
+
+void
+fn1 ()
+{
+ b = &&c; // { dg-error "not declared|not defined" }
+ goto *0;
+}
+
+void
+fn2 ()
+{
+c:
+ b = &&c; // { dg-error "not declared" }
+ goto *0;
+}