* [PATCH] c++: ICE with concepts TS multiple auto deduction [PR101886]
@ 2022-12-07 20:18 Patrick Palka
2022-12-19 16:00 ` Patrick Palka
2022-12-19 17:19 ` Jason Merrill
0 siblings, 2 replies; 3+ messages in thread
From: Patrick Palka @ 2022-12-07 20:18 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, Patrick Palka
In extract_autos_r, we need to reset TYPE_CANONICAL for the template
type parameter after adjusting its index, otherwise we end up with a
comptypes ICE for the below testcase. Note that such in-place type
adjustment isn't generallly safe to do since the type could be the
TYPE_CANONICAL of another (unadjusted) type, but in this case the
canonical auto (of some level and 0 index) is the first auto (of that
level) that's created, and so any auto that we do end up adjusting can't
be the canonical one.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?
PR c++/101886
gcc/cp/ChangeLog:
* pt.cc (extract_autos_r): Reset TYPE_CANONICAL after
adjusting the template type parameter's index. Simplify
by using TEMPLATE_TYPE_IDX. Add some sanity checks.
gcc/testsuite/ChangeLog:
* g++.dg/concepts/auto5.C: New test.
---
gcc/cp/pt.cc | 12 +++++++++---
gcc/testsuite/g++.dg/concepts/auto5.C | 9 +++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/concepts/auto5.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 24ed718ffbb..d05a49b1c11 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -29164,18 +29164,24 @@ extract_autos_r (tree t, void *data)
{
/* All the autos were built with index 0; fix that up now. */
tree *p = hash.find_slot (t, INSERT);
- unsigned idx;
+ int idx;
if (*p)
/* If this is a repeated constrained-type-specifier, use the index we
chose before. */
- idx = TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (*p));
+ idx = TEMPLATE_TYPE_IDX (*p);
else
{
/* Otherwise this is new, so use the current count. */
*p = t;
idx = hash.elements () - 1;
}
- TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (t)) = idx;
+ if (idx != TEMPLATE_TYPE_IDX (t))
+ {
+ gcc_checking_assert (TEMPLATE_TYPE_IDX (t) == 0);
+ gcc_checking_assert (TYPE_CANONICAL (t) != t);
+ TEMPLATE_TYPE_IDX (t) = idx;
+ TYPE_CANONICAL (t) = canonical_type_parameter (t);
+ }
}
/* Always keep walking. */
diff --git a/gcc/testsuite/g++.dg/concepts/auto5.C b/gcc/testsuite/g++.dg/concepts/auto5.C
new file mode 100644
index 00000000000..f1d653efd87
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/auto5.C
@@ -0,0 +1,9 @@
+// PR c++/101886
+// { dg-do compile { target c++17_only } }
+// { dg-options "-fconcepts-ts" }
+
+template<typename...> struct A { };
+
+A<int, int> a;
+A<auto, auto> b1 = a;
+A<auto, auto> b2 = a;
--
2.39.0.rc2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] c++: ICE with concepts TS multiple auto deduction [PR101886]
2022-12-07 20:18 [PATCH] c++: ICE with concepts TS multiple auto deduction [PR101886] Patrick Palka
@ 2022-12-19 16:00 ` Patrick Palka
2022-12-19 17:19 ` Jason Merrill
1 sibling, 0 replies; 3+ messages in thread
From: Patrick Palka @ 2022-12-19 16:00 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc-patches, jason
On Wed, 7 Dec 2022, Patrick Palka wrote:
> In extract_autos_r, we need to reset TYPE_CANONICAL for the template
> type parameter after adjusting its index, otherwise we end up with a
> comptypes ICE for the below testcase. Note that such in-place type
> adjustment isn't generallly safe to do since the type could be the
> TYPE_CANONICAL of another (unadjusted) type, but in this case the
> canonical auto (of some level and 0 index) is the first auto (of that
> level) that's created, and so any auto that we do end up adjusting can't
> be the canonical one.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?
Ping. FWIW this blocks the modules + std::source_location patch[1]
because the make_auto() call it adds to cxx_init_decl_processing would
otherwise cause us to ICE on the existing test g++.dg/concepts/auto1.C.
[1]: https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608127.html
>
> PR c++/101886
>
> gcc/cp/ChangeLog:
>
> * pt.cc (extract_autos_r): Reset TYPE_CANONICAL after
> adjusting the template type parameter's index. Simplify
> by using TEMPLATE_TYPE_IDX. Add some sanity checks.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/concepts/auto5.C: New test.
> ---
> gcc/cp/pt.cc | 12 +++++++++---
> gcc/testsuite/g++.dg/concepts/auto5.C | 9 +++++++++
> 2 files changed, 18 insertions(+), 3 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/concepts/auto5.C
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 24ed718ffbb..d05a49b1c11 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -29164,18 +29164,24 @@ extract_autos_r (tree t, void *data)
> {
> /* All the autos were built with index 0; fix that up now. */
> tree *p = hash.find_slot (t, INSERT);
> - unsigned idx;
> + int idx;
> if (*p)
> /* If this is a repeated constrained-type-specifier, use the index we
> chose before. */
> - idx = TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (*p));
> + idx = TEMPLATE_TYPE_IDX (*p);
> else
> {
> /* Otherwise this is new, so use the current count. */
> *p = t;
> idx = hash.elements () - 1;
> }
> - TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (t)) = idx;
> + if (idx != TEMPLATE_TYPE_IDX (t))
> + {
> + gcc_checking_assert (TEMPLATE_TYPE_IDX (t) == 0);
> + gcc_checking_assert (TYPE_CANONICAL (t) != t);
> + TEMPLATE_TYPE_IDX (t) = idx;
> + TYPE_CANONICAL (t) = canonical_type_parameter (t);
> + }
> }
>
> /* Always keep walking. */
> diff --git a/gcc/testsuite/g++.dg/concepts/auto5.C b/gcc/testsuite/g++.dg/concepts/auto5.C
> new file mode 100644
> index 00000000000..f1d653efd87
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/concepts/auto5.C
> @@ -0,0 +1,9 @@
> +// PR c++/101886
> +// { dg-do compile { target c++17_only } }
> +// { dg-options "-fconcepts-ts" }
> +
> +template<typename...> struct A { };
> +
> +A<int, int> a;
> +A<auto, auto> b1 = a;
> +A<auto, auto> b2 = a;
> --
> 2.39.0.rc2
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] c++: ICE with concepts TS multiple auto deduction [PR101886]
2022-12-07 20:18 [PATCH] c++: ICE with concepts TS multiple auto deduction [PR101886] Patrick Palka
2022-12-19 16:00 ` Patrick Palka
@ 2022-12-19 17:19 ` Jason Merrill
1 sibling, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2022-12-19 17:19 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 12/7/22 15:18, Patrick Palka wrote:
> In extract_autos_r, we need to reset TYPE_CANONICAL for the template
> type parameter after adjusting its index, otherwise we end up with a
> comptypes ICE for the below testcase. Note that such in-place type
> adjustment isn't generallly safe to do since the type could be the
> TYPE_CANONICAL of another (unadjusted) type, but in this case the
> canonical auto (of some level and 0 index) is the first auto (of that
> level) that's created, and so any auto that we do end up adjusting can't
> be the canonical one.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?
OK.
> PR c++/101886
>
> gcc/cp/ChangeLog:
>
> * pt.cc (extract_autos_r): Reset TYPE_CANONICAL after
> adjusting the template type parameter's index. Simplify
> by using TEMPLATE_TYPE_IDX. Add some sanity checks.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/concepts/auto5.C: New test.
> ---
> gcc/cp/pt.cc | 12 +++++++++---
> gcc/testsuite/g++.dg/concepts/auto5.C | 9 +++++++++
> 2 files changed, 18 insertions(+), 3 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/concepts/auto5.C
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 24ed718ffbb..d05a49b1c11 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -29164,18 +29164,24 @@ extract_autos_r (tree t, void *data)
> {
> /* All the autos were built with index 0; fix that up now. */
> tree *p = hash.find_slot (t, INSERT);
> - unsigned idx;
> + int idx;
> if (*p)
> /* If this is a repeated constrained-type-specifier, use the index we
> chose before. */
> - idx = TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (*p));
> + idx = TEMPLATE_TYPE_IDX (*p);
> else
> {
> /* Otherwise this is new, so use the current count. */
> *p = t;
> idx = hash.elements () - 1;
> }
> - TEMPLATE_PARM_IDX (TEMPLATE_TYPE_PARM_INDEX (t)) = idx;
> + if (idx != TEMPLATE_TYPE_IDX (t))
> + {
> + gcc_checking_assert (TEMPLATE_TYPE_IDX (t) == 0);
> + gcc_checking_assert (TYPE_CANONICAL (t) != t);
> + TEMPLATE_TYPE_IDX (t) = idx;
> + TYPE_CANONICAL (t) = canonical_type_parameter (t);
> + }
> }
>
> /* Always keep walking. */
> diff --git a/gcc/testsuite/g++.dg/concepts/auto5.C b/gcc/testsuite/g++.dg/concepts/auto5.C
> new file mode 100644
> index 00000000000..f1d653efd87
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/concepts/auto5.C
> @@ -0,0 +1,9 @@
> +// PR c++/101886
> +// { dg-do compile { target c++17_only } }
> +// { dg-options "-fconcepts-ts" }
> +
> +template<typename...> struct A { };
> +
> +A<int, int> a;
> +A<auto, auto> b1 = a;
> +A<auto, auto> b2 = a;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-19 17:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07 20:18 [PATCH] c++: ICE with concepts TS multiple auto deduction [PR101886] Patrick Palka
2022-12-19 16:00 ` Patrick Palka
2022-12-19 17:19 ` 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).