Commit 8a87daca by Jason Merrill Committed by Jason Merrill

PR c++/12245 - excessive memory use

	* constexpr.c (maybe_constant_value): Fold maybe_constant_value_1
	back in.  Don't cache constants.
	(maybe_constant_init): Don't cache constants.

From-SVN: r245169
parent 99be38ec
2017-02-03 Jason Merrill <jason@redhat.com> 2017-02-03 Jason Merrill <jason@redhat.com>
PR c++/12245 - excessive memory use
* constexpr.c (maybe_constant_value): Fold maybe_constant_value_1
back in. Don't cache constants.
(maybe_constant_init): Don't cache constants.
PR c++/79294 - ICE with invalid template argument PR c++/79294 - ICE with invalid template argument
* pt.c (convert_nontype_argument_function): Check value-dependence. * pt.c (convert_nontype_argument_function): Check value-dependence.
(convert_nontype_argument): Don't check it here for function ptrs. (convert_nontype_argument): Don't check it here for function ptrs.
......
...@@ -4777,8 +4777,10 @@ fold_simple (tree t) ...@@ -4777,8 +4777,10 @@ fold_simple (tree t)
Otherwise, if T does not have TREE_CONSTANT set, returns T. Otherwise, if T does not have TREE_CONSTANT set, returns T.
Otherwise, returns a version of T without TREE_CONSTANT. */ Otherwise, returns a version of T without TREE_CONSTANT. */
static tree static GTY((deletable)) hash_map<tree, tree> *cv_cache;
maybe_constant_value_1 (tree t, tree decl)
tree
maybe_constant_value (tree t, tree decl)
{ {
tree r; tree r;
...@@ -4791,6 +4793,14 @@ maybe_constant_value_1 (tree t, tree decl) ...@@ -4791,6 +4793,14 @@ maybe_constant_value_1 (tree t, tree decl)
} }
return t; return t;
} }
else if (CONSTANT_CLASS_P (t))
/* No caching or evaluation needed. */
return t;
if (cv_cache == NULL)
cv_cache = hash_map<tree, tree>::create_ggc (101);
if (tree *cached = cv_cache->get (t))
return *cached;
r = cxx_eval_outermost_constant_expr (t, true, true, decl); r = cxx_eval_outermost_constant_expr (t, true, true, decl);
gcc_checking_assert (r == t gcc_checking_assert (r == t
...@@ -4798,29 +4808,10 @@ maybe_constant_value_1 (tree t, tree decl) ...@@ -4798,29 +4808,10 @@ maybe_constant_value_1 (tree t, tree decl)
|| TREE_CODE (t) == VIEW_CONVERT_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR
|| (TREE_CONSTANT (t) && !TREE_CONSTANT (r)) || (TREE_CONSTANT (t) && !TREE_CONSTANT (r))
|| !cp_tree_equal (r, t)); || !cp_tree_equal (r, t));
cv_cache->put (t, r);
return r; return r;
} }
static GTY((deletable)) hash_map<tree, tree> *cv_cache;
/* If T is a constant expression, returns its reduced value.
Otherwise, if T does not have TREE_CONSTANT set, returns T.
Otherwise, returns a version of T without TREE_CONSTANT. */
tree
maybe_constant_value (tree t, tree decl)
{
if (cv_cache == NULL)
cv_cache = hash_map<tree, tree>::create_ggc (101);
if (tree *cached = cv_cache->get (t))
return *cached;
tree ret = maybe_constant_value_1 (t, decl);
cv_cache->put (t, ret);
return ret;
}
/* Dispose of the whole CV_CACHE. */ /* Dispose of the whole CV_CACHE. */
static void static void
...@@ -4916,6 +4907,8 @@ maybe_constant_init (tree t, tree decl) ...@@ -4916,6 +4907,8 @@ maybe_constant_init (tree t, tree decl)
t = TARGET_EXPR_INITIAL (t); t = TARGET_EXPR_INITIAL (t);
if (!potential_nondependent_static_init_expression (t)) if (!potential_nondependent_static_init_expression (t))
/* Don't try to evaluate it. */; /* Don't try to evaluate it. */;
else if (CONSTANT_CLASS_P (t))
/* No evaluation needed. */;
else else
t = cxx_eval_outermost_constant_expr (t, true, false, decl); t = cxx_eval_outermost_constant_expr (t, true, false, decl);
if (TREE_CODE (t) == TARGET_EXPR) if (TREE_CODE (t) == TARGET_EXPR)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment