public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: ICE with computed gotos [PR115469]
@ 2024-06-26 22:04 Marek Polacek
  2024-07-01 18:44 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2024-06-26 22:04 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
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 (decl_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.
---
 gcc/cp/decl.cc                     | 19 +++++++++++++++----
 gcc/testsuite/g++.dg/ext/label17.C | 18 ++++++++++++++++++
 2 files changed, 33 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/label17.C

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 03deb1493a4..e5696079c28 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -514,6 +514,19 @@ 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.  */
+
+static bool
+decl_with_nontrivial_dtor_p (const_tree t)
+{
+  if (error_operand_p (t))
+    return false;
+
+  return (VAR_P (t)
+	  && !TREE_STATIC (t)
+	  && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
+}
+
 /* Update data for defined and undefined labels when leaving a scope.  */
 
 int
@@ -575,8 +588,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 (decl_with_nontrivial_dtor_p (d))
 		    vec_safe_push (cg, d);
 	      }
 
@@ -4003,8 +4015,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 (decl_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 00000000000..076ef1f798e
--- /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;
+}

base-commit: 0731985920cdeeeb028f03ddb8a7f035565c1594
-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] c++: ICE with computed gotos [PR115469]
  2024-06-26 22:04 [PATCH] c++: ICE with computed gotos [PR115469] Marek Polacek
@ 2024-07-01 18:44 ` Jason Merrill
  2024-07-01 21:09   ` [PATCH v2] " Marek Polacek
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2024-07-01 18:44 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 6/26/24 6:04 PM, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> -- >8 --
> 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 (decl_with_nontrivial_dtor_p): New.

This name doesn't suggest non-static variable to me.  Maybe 
automatic_var_with...?

While we're at it, we should also avoid complaining about thread-local 
by checking decl_storage_duration == dk_auto, since [stmt.dcl]/2 is 
specifically about automatic.

> 	(poplevel_named_label_1): Use it.
> 	(check_goto_1): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/ext/label17.C: New test.
> ---
>   gcc/cp/decl.cc                     | 19 +++++++++++++++----
>   gcc/testsuite/g++.dg/ext/label17.C | 18 ++++++++++++++++++
>   2 files changed, 33 insertions(+), 4 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/ext/label17.C
> 
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 03deb1493a4..e5696079c28 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -514,6 +514,19 @@ 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.  */
> +
> +static bool
> +decl_with_nontrivial_dtor_p (const_tree t)
> +{
> +  if (error_operand_p (t))
> +    return false;
> +
> +  return (VAR_P (t)
> +	  && !TREE_STATIC (t)
> +	  && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
> +}
> +
>   /* Update data for defined and undefined labels when leaving a scope.  */
>   
>   int
> @@ -575,8 +588,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 (decl_with_nontrivial_dtor_p (d))
>   		    vec_safe_push (cg, d);
>   	      }
>   
> @@ -4003,8 +4015,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 (decl_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 00000000000..076ef1f798e
> --- /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;
> +}
> 
> base-commit: 0731985920cdeeeb028f03ddb8a7f035565c1594


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] c++: ICE with computed gotos [PR115469]
  2024-07-01 18:44 ` Jason Merrill
@ 2024-07-01 21:09   ` Marek Polacek
  2024-07-01 22:09     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2024-07-01 21:09 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

On Mon, Jul 01, 2024 at 02:44:56PM -0400, Jason Merrill wrote:
> On 6/26/24 6:04 PM, Marek Polacek wrote:
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> > 
> > -- >8 --
> > 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 (decl_with_nontrivial_dtor_p): New.
> 
> This name doesn't suggest non-static variable to me.  Maybe
> automatic_var_with...?

Sounds good.

> While we're at it, we should also avoid complaining about thread-local by
> checking decl_storage_duration == dk_auto, since [stmt.dcl]/2 is
> specifically about automatic.

Done here.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
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.
---
 gcc/cp/decl.cc                     | 21 +++++++++++++++++----
 gcc/testsuite/g++.dg/ext/label17.C | 18 ++++++++++++++++++
 2 files changed, 35 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/label17.C

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 03deb1493a4..d439b04bfa7 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -514,6 +514,21 @@ 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)
+	  && !TREE_STATIC (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 +590,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 +4017,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 00000000000..076ef1f798e
--- /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;
+}

base-commit: c847dcf94499da62e5a28921b404e6e561645d99
-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] c++: ICE with computed gotos [PR115469]
  2024-07-01 21:09   ` [PATCH v2] " Marek Polacek
@ 2024-07-01 22:09     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2024-07-01 22:09 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On 7/1/24 5:09 PM, Marek Polacek wrote:
> On Mon, Jul 01, 2024 at 02:44:56PM -0400, Jason Merrill wrote:
>> On 6/26/24 6:04 PM, Marek Polacek wrote:
>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>>>
>>> -- >8 --
>>> 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 (decl_with_nontrivial_dtor_p): New.
>>
>> This name doesn't suggest non-static variable to me.  Maybe
>> automatic_var_with...?
> 
> Sounds good.
> 
>> While we're at it, we should also avoid complaining about thread-local by
>> checking decl_storage_duration == dk_auto, since [stmt.dcl]/2 is
>> specifically about automatic.
> 
> Done here.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> -- >8 --
> 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.
> ---
>   gcc/cp/decl.cc                     | 21 +++++++++++++++++----
>   gcc/testsuite/g++.dg/ext/label17.C | 18 ++++++++++++++++++
>   2 files changed, 35 insertions(+), 4 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/ext/label17.C
> 
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 03deb1493a4..d439b04bfa7 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -514,6 +514,21 @@ 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)
> +	  && !TREE_STATIC (t)

Checking TREE_STATIC is redundant with checking decl_storage_duration. 
OK without the above line.

> +	  && 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 +590,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 +4017,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 00000000000..076ef1f798e
> --- /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;
> +}
> 
> base-commit: c847dcf94499da62e5a28921b404e6e561645d99


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-01 22:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-26 22:04 [PATCH] c++: ICE with computed gotos [PR115469] Marek Polacek
2024-07-01 18:44 ` Jason Merrill
2024-07-01 21:09   ` [PATCH v2] " Marek Polacek
2024-07-01 22:09     ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).