public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: folding non-dep enumerator from current inst [PR115139]
@ 2024-05-17 16:05 Patrick Palka
  2024-05-17 16:18 ` Marek Polacek
  2024-05-21 18:05 ` Jason Merrill
  0 siblings, 2 replies; 3+ messages in thread
From: Patrick Palka @ 2024-05-17 16:05 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/14?

-- >8 --

After the tsubst_copy removal r14-4796-g3e3d73ed5e85e7 GCC 14 ICEs during
fold_non_dependent_expr for 'e1 | e2' ultimately because we no longer exit
early when substituting the CONST_DECLs for e1 and e2 with args=NULL_TREE,
during which we try substituting the class context A<Ts...> (also with
args=NULL_TREE) which ends up ICEing from tsubst_pack_expansion (due to
processing_template_decl being cleared).

Incidentally, the ICE went away on trunk ever since the tsubst_aggr_type
removal r15-123-gf04dc89a991ddc since it made the CONST_DECL case of
tsubst_expr use tsubst to substitute the context, which does short circuit
for empty args and so avoids the ICE.

This patch fixes this ICE for GCC 14 by narrowly restoring the early exit
for empty args that was present in tsubst_copy when substituting an
enumerator CONST_DECL.  We might as well apply this to trunk too, as a
very minor optimization.

	PR c++/115139

gcc/cp/ChangeLog:

	* pt.cc (tsubst_expr) <case CONST_DECL>: Exit early if args
	is empty.

gcc/testsuite/ChangeLog:

	* g++.dg/template/non-dependent33.C: New test.
---
 gcc/cp/pt.cc                                    |  2 +-
 gcc/testsuite/g++.dg/template/non-dependent33.C | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/non-dependent33.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 32640f8e946..e185e3d8941 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -21519,7 +21519,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 
 	if (DECL_TEMPLATE_PARM_P (t))
 	  RETURN (RECUR (DECL_INITIAL (t)));
-	if (!uses_template_parms (DECL_CONTEXT (t)))
+	if (!args || !uses_template_parms (DECL_CONTEXT (t)))
 	  RETURN (t);
 
 	/* Unfortunately, we cannot just call lookup_name here.
diff --git a/gcc/testsuite/g++.dg/template/non-dependent33.C b/gcc/testsuite/g++.dg/template/non-dependent33.C
new file mode 100644
index 00000000000..2f1dd8a214c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent33.C
@@ -0,0 +1,11 @@
+// PR c++/115139
+// { dg-do compile { target c++11 } }
+
+template<class... Ts>
+class A {
+  enum E {
+    e1 = 1,
+    e2 = 2,
+    e3 = e1 | e2,
+  };
+};
-- 
2.45.1.204.gd8ab1d464d


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

* Re: [PATCH] c++: folding non-dep enumerator from current inst [PR115139]
  2024-05-17 16:05 [PATCH] c++: folding non-dep enumerator from current inst [PR115139] Patrick Palka
@ 2024-05-17 16:18 ` Marek Polacek
  2024-05-21 18:05 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Polacek @ 2024-05-17 16:18 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, jason

On Fri, May 17, 2024 at 12:05:15PM -0400, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/14?

This patch looks good to me, thanks.
 
> -- >8 --
> 
> After the tsubst_copy removal r14-4796-g3e3d73ed5e85e7 GCC 14 ICEs during
> fold_non_dependent_expr for 'e1 | e2' ultimately because we no longer exit
> early when substituting the CONST_DECLs for e1 and e2 with args=NULL_TREE,
> during which we try substituting the class context A<Ts...> (also with
> args=NULL_TREE) which ends up ICEing from tsubst_pack_expansion (due to
> processing_template_decl being cleared).
> 
> Incidentally, the ICE went away on trunk ever since the tsubst_aggr_type
> removal r15-123-gf04dc89a991ddc since it made the CONST_DECL case of
> tsubst_expr use tsubst to substitute the context, which does short circuit
> for empty args and so avoids the ICE.
> 
> This patch fixes this ICE for GCC 14 by narrowly restoring the early exit
> for empty args that was present in tsubst_copy when substituting an
> enumerator CONST_DECL.  We might as well apply this to trunk too, as a
> very minor optimization.
> 
> 	PR c++/115139
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (tsubst_expr) <case CONST_DECL>: Exit early if args
> 	is empty.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/non-dependent33.C: New test.
> ---
>  gcc/cp/pt.cc                                    |  2 +-
>  gcc/testsuite/g++.dg/template/non-dependent33.C | 11 +++++++++++
>  2 files changed, 12 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.dg/template/non-dependent33.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 32640f8e946..e185e3d8941 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -21519,7 +21519,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
>  
>  	if (DECL_TEMPLATE_PARM_P (t))
>  	  RETURN (RECUR (DECL_INITIAL (t)));
> -	if (!uses_template_parms (DECL_CONTEXT (t)))
> +	if (!args || !uses_template_parms (DECL_CONTEXT (t)))
>  	  RETURN (t);
>  
>  	/* Unfortunately, we cannot just call lookup_name here.
> diff --git a/gcc/testsuite/g++.dg/template/non-dependent33.C b/gcc/testsuite/g++.dg/template/non-dependent33.C
> new file mode 100644
> index 00000000000..2f1dd8a214c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/non-dependent33.C
> @@ -0,0 +1,11 @@
> +// PR c++/115139
> +// { dg-do compile { target c++11 } }
> +
> +template<class... Ts>
> +class A {
> +  enum E {
> +    e1 = 1,
> +    e2 = 2,
> +    e3 = e1 | e2,
> +  };
> +};
> -- 
> 2.45.1.204.gd8ab1d464d
> 

Marek


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

* Re: [PATCH] c++: folding non-dep enumerator from current inst [PR115139]
  2024-05-17 16:05 [PATCH] c++: folding non-dep enumerator from current inst [PR115139] Patrick Palka
  2024-05-17 16:18 ` Marek Polacek
@ 2024-05-21 18:05 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2024-05-21 18:05 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 5/17/24 12:05, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/14?

OK for both.

> -- >8 --
> 
> After the tsubst_copy removal r14-4796-g3e3d73ed5e85e7 GCC 14 ICEs during
> fold_non_dependent_expr for 'e1 | e2' ultimately because we no longer exit
> early when substituting the CONST_DECLs for e1 and e2 with args=NULL_TREE,
> during which we try substituting the class context A<Ts...> (also with
> args=NULL_TREE) which ends up ICEing from tsubst_pack_expansion (due to
> processing_template_decl being cleared).
> 
> Incidentally, the ICE went away on trunk ever since the tsubst_aggr_type
> removal r15-123-gf04dc89a991ddc since it made the CONST_DECL case of
> tsubst_expr use tsubst to substitute the context, which does short circuit
> for empty args and so avoids the ICE.
> 
> This patch fixes this ICE for GCC 14 by narrowly restoring the early exit
> for empty args that was present in tsubst_copy when substituting an
> enumerator CONST_DECL.  We might as well apply this to trunk too, as a
> very minor optimization.
> 
> 	PR c++/115139
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (tsubst_expr) <case CONST_DECL>: Exit early if args
> 	is empty.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/non-dependent33.C: New test.
> ---
>   gcc/cp/pt.cc                                    |  2 +-
>   gcc/testsuite/g++.dg/template/non-dependent33.C | 11 +++++++++++
>   2 files changed, 12 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/template/non-dependent33.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 32640f8e946..e185e3d8941 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -21519,7 +21519,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
>   
>   	if (DECL_TEMPLATE_PARM_P (t))
>   	  RETURN (RECUR (DECL_INITIAL (t)));
> -	if (!uses_template_parms (DECL_CONTEXT (t)))
> +	if (!args || !uses_template_parms (DECL_CONTEXT (t)))
>   	  RETURN (t);
>   
>   	/* Unfortunately, we cannot just call lookup_name here.
> diff --git a/gcc/testsuite/g++.dg/template/non-dependent33.C b/gcc/testsuite/g++.dg/template/non-dependent33.C
> new file mode 100644
> index 00000000000..2f1dd8a214c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/non-dependent33.C
> @@ -0,0 +1,11 @@
> +// PR c++/115139
> +// { dg-do compile { target c++11 } }
> +
> +template<class... Ts>
> +class A {
> +  enum E {
> +    e1 = 1,
> +    e2 = 2,
> +    e3 = e1 | e2,
> +  };
> +};


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

end of thread, other threads:[~2024-05-21 18:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-17 16:05 [PATCH] c++: folding non-dep enumerator from current inst [PR115139] Patrick Palka
2024-05-17 16:18 ` Marek Polacek
2024-05-21 18:05 ` 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).