From: Jason Merrill Date: Fri, 8 Apr 2011 06:08:13 +0000 (-0400) Subject: re PR c++/48481 (C++ overloading memory hog) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3a2cb4d037cc66a0b6567d944cbc9450adf11814;p=gcc.git re PR c++/48481 (C++ overloading memory hog) PR c++/48481 * cp-tree.h (OVL_ARG_DEPENDENT): New. * name-lookup.c (add_function): Set it. * semantics.c (finish_call_expr): Free OVERLOADs if it's set. From-SVN: r172163 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2cb394f00e6..307272bef42 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2011-04-07 Jason Merrill + PR c++/48481 + * cp-tree.h (OVL_ARG_DEPENDENT): New. + * name-lookup.c (add_function): Set it. + * semantics.c (finish_call_expr): Free OVERLOADs if it's set. + PR c++/48481 * call.c (build_user_type_conversion_1): Use lookup_fnfields_slot. Release unused vector. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ea251a8dbbd..885b31cd61a 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -317,6 +317,9 @@ typedef struct ptrmem_cst * ptrmem_cst_t; This is not to confuse with being used somewhere, which is not important for this node. */ #define OVL_USED(NODE) TREE_USED (NODE) +/* If set, this OVERLOAD was created for argument-dependent lookup + and can be freed afterward. */ +#define OVL_ARG_DEPENDENT(NODE) TREE_LANG_FLAG_0 (OVERLOAD_CHECK (NODE)) struct GTY(()) tree_overload { struct tree_common common; diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 18e34417b26..696a8f5fdcb 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -4725,7 +4725,11 @@ add_function (struct arg_lookup *k, tree fn) else if (fn == k->functions) ; else - k->functions = build_overload (fn, k->functions); + { + k->functions = build_overload (fn, k->functions); + if (TREE_CODE (k->functions) == OVERLOAD) + OVL_ARG_DEPENDENT (k->functions) = true; + } return false; } diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 30175afaaa5..2184a53558e 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2160,6 +2160,25 @@ finish_call_expr (tree fn, VEC(tree,gc) **args, bool disallow_virtual, result = convert_from_reference (result); } + if (koenig_p) + { + /* Free garbage OVERLOADs from arg-dependent lookup. */ + tree next = NULL_TREE; + for (fn = orig_fn; + fn && TREE_CODE (fn) == OVERLOAD && OVL_ARG_DEPENDENT (fn); + fn = next) + { + if (processing_template_decl) + /* In a template, we'll re-use them at instantiation time. */ + OVL_ARG_DEPENDENT (fn) = false; + else + { + next = OVL_CHAIN (fn); + ggc_free (fn); + } + } + } + return result; }