Commit 861c3495 by Gary Benson Committed by Gary Benson

cp-demangle.c (struct d_component_stack): New structure.

libiberty/
2014-05-08  Gary Benson  <gbenson@redhat.com>

	* cp-demangle.c (struct d_component_stack): New structure.
	(struct d_print_info): New field component_stack.
	(d_print_init): Initialize the above.
	(d_print_comp_inner): Renamed from d_print_comp.
	Do not restore template stack if it would cause a loop.
	(d_print_comp): New function.
	* testsuite/demangle-expected: New test cases.

From-SVN: r210205
parent d1f1a283
2014-05-08 Gary Benson <gbenson@redhat.com>
* cp-demangle.c (struct d_component_stack): New structure.
(struct d_print_info): New field component_stack.
(d_print_init): Initialize the above.
(d_print_comp_inner): Renamed from d_print_comp.
Do not restore template stack if it would cause a loop.
(d_print_comp): New function.
* testsuite/demangle-expected: New test cases.
2014-04-17 Jakub Jelinek <jakub@redhat.com> 2014-04-17 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/56781 PR sanitizer/56781
......
...@@ -275,6 +275,16 @@ struct d_growable_string ...@@ -275,6 +275,16 @@ struct d_growable_string
int allocation_failure; int allocation_failure;
}; };
/* Stack of components, innermost first, used to avoid loops. */
struct d_component_stack
{
/* This component. */
const struct demangle_component *dc;
/* This component's parent. */
const struct d_component_stack *parent;
};
/* A demangle component and some scope captured when it was first /* A demangle component and some scope captured when it was first
traversed. */ traversed. */
...@@ -327,6 +337,8 @@ struct d_print_info ...@@ -327,6 +337,8 @@ struct d_print_info
int pack_index; int pack_index;
/* Number of d_print_flush calls so far. */ /* Number of d_print_flush calls so far. */
unsigned long int flush_count; unsigned long int flush_count;
/* Stack of components, innermost first, used to avoid loops. */
const struct d_component_stack *component_stack;
/* Array of saved scopes for evaluating substitutions. */ /* Array of saved scopes for evaluating substitutions. */
struct d_saved_scope *saved_scopes; struct d_saved_scope *saved_scopes;
/* Index of the next unused saved scope in the above array. */ /* Index of the next unused saved scope in the above array. */
...@@ -3934,6 +3946,8 @@ d_print_init (struct d_print_info *dpi, demangle_callbackref callback, ...@@ -3934,6 +3946,8 @@ d_print_init (struct d_print_info *dpi, demangle_callbackref callback,
dpi->demangle_failure = 0; dpi->demangle_failure = 0;
dpi->component_stack = NULL;
dpi->saved_scopes = NULL; dpi->saved_scopes = NULL;
dpi->next_saved_scope = 0; dpi->next_saved_scope = 0;
dpi->num_saved_scopes = 0; dpi->num_saved_scopes = 0;
...@@ -4269,8 +4283,8 @@ d_get_saved_scope (struct d_print_info *dpi, ...@@ -4269,8 +4283,8 @@ d_get_saved_scope (struct d_print_info *dpi,
/* Subroutine to handle components. */ /* Subroutine to handle components. */
static void static void
d_print_comp (struct d_print_info *dpi, int options, d_print_comp_inner (struct d_print_info *dpi, int options,
const struct demangle_component *dc) const struct demangle_component *dc)
{ {
/* Magic variable to let reference smashing skip over the next modifier /* Magic variable to let reference smashing skip over the next modifier
without needing to modify *dc. */ without needing to modify *dc. */
...@@ -4673,11 +4687,30 @@ d_print_comp (struct d_print_info *dpi, int options, ...@@ -4673,11 +4687,30 @@ d_print_comp (struct d_print_info *dpi, int options,
} }
else else
{ {
const struct d_component_stack *dcse;
int found_self_or_parent = 0;
/* This traversal is reentering SUB as a substition. /* This traversal is reentering SUB as a substition.
Restore the original templates temporarily. */ If we are not beneath SUB or DC in the tree then we
saved_templates = dpi->templates; need to restore SUB's template stack temporarily. */
dpi->templates = scope->templates; for (dcse = dpi->component_stack; dcse != NULL;
need_template_restore = 1; dcse = dcse->parent)
{
if (dcse->dc == sub
|| (dcse->dc == dc
&& dcse != dpi->component_stack))
{
found_self_or_parent = 1;
break;
}
}
if (!found_self_or_parent)
{
saved_templates = dpi->templates;
dpi->templates = scope->templates;
need_template_restore = 1;
}
} }
a = d_lookup_template_argument (dpi, sub); a = d_lookup_template_argument (dpi, sub);
...@@ -5316,6 +5349,21 @@ d_print_comp (struct d_print_info *dpi, int options, ...@@ -5316,6 +5349,21 @@ d_print_comp (struct d_print_info *dpi, int options,
} }
} }
static void
d_print_comp (struct d_print_info *dpi, int options,
const struct demangle_component *dc)
{
struct d_component_stack self;
self.dc = dc;
self.parent = dpi->component_stack;
dpi->component_stack = &self;
d_print_comp_inner (dpi, options, dc);
dpi->component_stack = self.parent;
}
/* Print a Java dentifier. For Java we try to handle encoded extended /* Print a Java dentifier. For Java we try to handle encoded extended
Unicode characters. The C++ ABI doesn't mention Unicode encoding, Unicode characters. The C++ ABI doesn't mention Unicode encoding,
so we don't it for C++. Characters are encoded as so we don't it for C++. Characters are encoded as
......
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