public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-7227] c++: bad ggc_free in try_class_unification [PR109556]
@ 2023-04-19 17:14 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2023-04-19 17:14 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:90361bc6f4ffffedb444e86380b6d1e08475fa74

commit r13-7227-g90361bc6f4ffffedb444e86380b6d1e08475fa74
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Apr 19 13:07:46 2023 -0400

    c++: bad ggc_free in try_class_unification [PR109556]
    
    Aside from correcting how try_class_unification copies multi-dimensional
    'targs', r13-377-g3e948d645bc908 also made it ggc_free this copy as an
    optimization.  But this is wrong since the call to unify within might've
    captured the args in persistent memory such as the satisfaction cache
    (as part of constrained auto deduction).
    
            PR c++/109556
    
    gcc/cp/ChangeLog:
    
            * pt.cc (try_class_unification): Don't ggc_free the copy of
            'targs'.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/concepts-placeholder13.C: New test.
    
    (cherry picked from commit 5e284ebbc3082c5a8974d24e3a0977aa48f3cc60)

Diff:
---
 gcc/cp/pt.cc                                        |  5 -----
 gcc/testsuite/g++.dg/cpp2a/concepts-placeholder13.C | 18 ++++++++++++++++++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index e065ace5c55..68a056acf8b 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -23895,11 +23895,6 @@ try_class_unification (tree tparms, tree targs, tree parm, tree arg,
     err = unify (tparms, targs, CLASSTYPE_TI_ARGS (parm),
 		 CLASSTYPE_TI_ARGS (arg), UNIFY_ALLOW_NONE, explain_p);
 
-  if (TMPL_ARGS_HAVE_MULTIPLE_LEVELS (targs))
-    for (tree level : tree_vec_range (targs))
-      ggc_free (level);
-  ggc_free (targs);
-
   return err ? NULL_TREE : arg;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder13.C b/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder13.C
new file mode 100644
index 00000000000..ac9f84524d3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder13.C
@@ -0,0 +1,18 @@
+// PR c++/109556
+// { dg-do compile { target c++20 } }
+
+template<class T, auto N>
+concept C = (N != 0);
+
+template<auto N, auto M>
+struct A { };
+
+template<auto N, C<N> auto M>
+void f(A<N, M>);
+
+int main() {
+  f(A<1, 42>{});
+  f(A<2, 42>{});
+  f(A<1, 43>{});
+  f(A<2, 43>{});
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-19 17:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-19 17:14 [gcc r13-7227] c++: bad ggc_free in try_class_unification [PR109556] Patrick Palka

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).