re PR c++/48481 (C++ overloading memory hog)
authorJason Merrill <jason@redhat.com>
Fri, 8 Apr 2011 06:08:13 +0000 (02:08 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 8 Apr 2011 06:08:13 +0000 (02:08 -0400)
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

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/name-lookup.c
gcc/cp/semantics.c

index 2cb394f..307272b 100644 (file)
@@ -1,6 +1,11 @@
 2011-04-07  Jason Merrill  <jason@redhat.com>
 
        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.
 
index ea251a8..885b31c 100644 (file)
@@ -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;
index 18e3441..696a8f5 100644 (file)
@@ -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;
 }
index 30175af..2184a53 100644 (file)
@@ -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;
 }