Commit 2dc589be by Jakub Jelinek Committed by Jakub Jelinek

re PR sanitizer/81929 (exponential slowdown in undefined behavior sanitizer for streaming)

	PR sanitizer/81929
	* tree.c (struct replace_placeholders_t): Add pset field.
	(replace_placeholders_r): Call cp_walk_tree with d->pset as
	last argument instead of NULL.  Formatting fix.
	(replace_placeholders): Add pset variable, add its address
	into data.  Pass &pset instead of NULL to cp_walk_tree.

	* g++.dg/ubsan/pr81929.C: New test.

From-SVN: r253106
parent c90df0d2
2017-09-22 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/81929
* tree.c (struct replace_placeholders_t): Add pset field.
(replace_placeholders_r): Call cp_walk_tree with d->pset as
last argument instead of NULL. Formatting fix.
(replace_placeholders): Add pset variable, add its address
into data. Pass &pset instead of NULL to cp_walk_tree.
2017-09-22 David Malcolm <dmalcolm@redhat.com> 2017-09-22 David Malcolm <dmalcolm@redhat.com>
* call.c (get_fndecl_argument_location): New function. * call.c (get_fndecl_argument_location): New function.
......
...@@ -3063,6 +3063,7 @@ struct replace_placeholders_t ...@@ -3063,6 +3063,7 @@ struct replace_placeholders_t
{ {
tree obj; /* The object to be substituted for a PLACEHOLDER_EXPR. */ tree obj; /* The object to be substituted for a PLACEHOLDER_EXPR. */
bool seen; /* Whether we've encountered a PLACEHOLDER_EXPR. */ bool seen; /* Whether we've encountered a PLACEHOLDER_EXPR. */
hash_set<tree> *pset; /* To avoid walking same trees multiple times. */
}; };
/* Like substitute_placeholder_in_expr, but handle C++ tree codes and /* Like substitute_placeholder_in_expr, but handle C++ tree codes and
...@@ -3085,8 +3086,8 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_) ...@@ -3085,8 +3086,8 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
case PLACEHOLDER_EXPR: case PLACEHOLDER_EXPR:
{ {
tree x = obj; tree x = obj;
for (; !(same_type_ignoring_top_level_qualifiers_p for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t),
(TREE_TYPE (*t), TREE_TYPE (x))); TREE_TYPE (x));
x = TREE_OPERAND (x, 0)) x = TREE_OPERAND (x, 0))
gcc_assert (TREE_CODE (x) == COMPONENT_REF); gcc_assert (TREE_CODE (x) == COMPONENT_REF);
*t = x; *t = x;
...@@ -3118,8 +3119,7 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_) ...@@ -3118,8 +3119,7 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
valp = &TARGET_EXPR_INITIAL (*valp); valp = &TARGET_EXPR_INITIAL (*valp);
} }
d->obj = subob; d->obj = subob;
cp_walk_tree (valp, replace_placeholders_r, cp_walk_tree (valp, replace_placeholders_r, data_, d->pset);
data_, NULL);
d->obj = obj; d->obj = obj;
} }
*walk_subtrees = false; *walk_subtrees = false;
...@@ -3151,10 +3151,11 @@ replace_placeholders (tree exp, tree obj, bool *seen_p) ...@@ -3151,10 +3151,11 @@ replace_placeholders (tree exp, tree obj, bool *seen_p)
return exp; return exp;
tree *tp = &exp; tree *tp = &exp;
replace_placeholders_t data = { obj, false }; hash_set<tree> pset;
replace_placeholders_t data = { obj, false, &pset };
if (TREE_CODE (exp) == TARGET_EXPR) if (TREE_CODE (exp) == TARGET_EXPR)
tp = &TARGET_EXPR_INITIAL (exp); tp = &TARGET_EXPR_INITIAL (exp);
cp_walk_tree (tp, replace_placeholders_r, &data, NULL); cp_walk_tree (tp, replace_placeholders_r, &data, &pset);
if (seen_p) if (seen_p)
*seen_p = data.seen; *seen_p = data.seen;
return exp; return exp;
......
2017-09-22 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/81929
* g++.dg/ubsan/pr81929.C: New test.
2017-09-22 Richard Sandiford <richard.sandiford@linaro.org> 2017-09-22 Richard Sandiford <richard.sandiford@linaro.org>
PR tree-optimization/82289 PR tree-optimization/82289
......
// PR sanitizer/81929
// { dg-do compile }
// { dg-options "-std=c++14 -fsanitize=undefined" }
struct S { S &operator<< (long); S foo (); S (); };
void
bar ()
{
static_cast<S&>(S () << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0
<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0
<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0
<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0).foo ();
}
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