From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 466ED3858D33; Wed, 19 Apr 2023 17:14:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 466ED3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681924493; bh=j3eVDmmmcwvVd1zVC1RdmFrDY63qid0O0eYxKhutwBw=; h=From:To:Subject:Date:From; b=UOzlQw7SRzGC8L1N1e2nKNgOs/PMMKtTp1H5Led/KTibI64sdJ9uLaaCrWlJbpCZy n43n0OAW0xak/hq8N7QYpHolJbppV74G9zmQkzmIufU/ol/P/l4SpRAZxkcZyUm+m7 hsZJOYD6RGjeMX2uk03GzFjbfMPssFbaztIuqq8U= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-7227] c++: bad ggc_free in try_class_unification [PR109556] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 68997d4323cdcbd4c626b04f6f29df835694056a X-Git-Newrev: 90361bc6f4ffffedb444e86380b6d1e08475fa74 Message-Id: <20230419171453.466ED3858D33@sourceware.org> Date: Wed, 19 Apr 2023 17:14:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:90361bc6f4ffffedb444e86380b6d1e08475fa74 commit r13-7227-g90361bc6f4ffffedb444e86380b6d1e08475fa74 Author: Patrick Palka 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 +concept C = (N != 0); + +template +struct A { }; + +template auto M> +void f(A); + +int main() { + f(A<1, 42>{}); + f(A<2, 42>{}); + f(A<1, 43>{}); + f(A<2, 43>{}); +}