aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2024-10-03 16:31:00 -0400
committerJason Merrill <jason@redhat.com>2024-10-03 16:31:00 -0400
commitd77f073ce66cedbcbb22357c49b9ef19e1b61a43 (patch)
tree51bf367a73178f023a3c519c7b3f78fb42b3092b
parent547219f41f049083cda55929ae1c900195993504 (diff)
downloadgcc-d77f073ce66cedbcbb22357c49b9ef19e1b61a43.zip
gcc-d77f073ce66cedbcbb22357c49b9ef19e1b61a43.tar.gz
gcc-d77f073ce66cedbcbb22357c49b9ef19e1b61a43.tar.bz2
c++: free garbage vec in coerce_template_parms
coerce_template_parms can create two different vecs for the inner template arguments, new_inner_args and (potentially) the result of expand_template_argument_pack. One or the other, or possibly both, end up being garbage: in the typical case, the expanded vec is garbage because it's only used as the source for convert_template_argument. In some dependent cases, the new vec is garbage because we decide to return the original args instead. In these cases, ggc_free the garbage vec to reduce the memory overhead of overload resolution. gcc/cp/ChangeLog: * pt.cc (coerce_template_parms): Free garbage vecs. Co-authored-by: Richard Biener <rguenther@suse.de>
-rw-r--r--gcc/cp/pt.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 20affcd..4ceae1d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -9275,6 +9275,7 @@ coerce_template_parms (tree parms,
{
/* We don't know how many args we have yet, just use the
unconverted (and still packed) ones for now. */
+ ggc_free (new_inner_args);
new_inner_args = orig_inner_args;
arg_idx = nargs;
break;
@@ -9329,7 +9330,8 @@ coerce_template_parms (tree parms,
= make_pack_expansion (conv, complain);
/* We don't know how many args we have yet, just
- use the unconverted ones for now. */
+ use the unconverted (but unpacked) ones for now. */
+ ggc_free (new_inner_args);
new_inner_args = inner_args;
arg_idx = nargs;
break;
@@ -9442,6 +9444,12 @@ coerce_template_parms (tree parms,
SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_inner_args,
TREE_VEC_LENGTH (new_inner_args));
+ /* If we expanded packs in inner_args and aren't returning it now, the
+ expanded vec is garbage. */
+ if (inner_args != new_inner_args
+ && inner_args != orig_inner_args)
+ ggc_free (inner_args);
+
return return_full_args ? new_args : new_inner_args;
}