summaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2016-07-15 18:38:15 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2016-07-15 18:38:15 +0000
commit17fdf85c89efe69938813368d5f8bfa8027b1c03 (patch)
tree1ee707547ea5521e317e522ed83b170324ec4a05 /libiberty
parent0238e35ef85e0aa66fb4c179ff6a0f16e127f542 (diff)
PR c++/71814 - mangling sizeof... (sP and sZ)
gcc/cp/ * mangle.c (write_expression): Handle sizeof... an argument pack. libiberty/ * cp-demangle.c (cplus_demangle_operators): Add sP and sZ. (d_print_comp_inner): Handle them. (d_template_args_1): Split out from d_template_args. (d_args_length): New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@238389 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/ChangeLog7
-rw-r--r--libiberty/cp-demangle.c62
-rw-r--r--libiberty/testsuite/demangle-expected6
3 files changed, 70 insertions, 5 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 317bd63c0544..3b50cdcd5b49 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,10 @@
+2016-07-15 Jason Merrill <jason@redhat.com>
+
+ * cp-demangle.c (cplus_demangle_operators): Add sP and sZ.
+ (d_print_comp_inner): Handle them.
+ (d_template_args_1): Split out from d_template_args.
+ (d_args_length): New.
+
2016-07-13 Marcel BÃhme <boehme.marcel@gmail.com>
PR c++/70926
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 7f664b9c5c0d..56d3bcb28fd3 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -466,6 +466,7 @@ static struct demangle_component *
d_template_param (struct d_info *);
static struct demangle_component *d_template_args (struct d_info *);
+static struct demangle_component *d_template_args_1 (struct d_info *);
static struct demangle_component *
d_template_arg (struct d_info *);
@@ -1795,6 +1796,8 @@ const struct demangle_operator_info cplus_demangle_operators[] =
{ "rc", NL ("reinterpret_cast"), 2 },
{ "rm", NL ("%"), 2 },
{ "rs", NL (">>"), 2 },
+ { "sP", NL ("sizeof..."), 1 },
+ { "sZ", NL ("sizeof..."), 1 },
{ "sc", NL ("static_cast"), 2 },
{ "st", NL ("sizeof "), 1 },
{ "sz", NL ("sizeof "), 1 },
@@ -2995,6 +2998,19 @@ d_template_param (struct d_info *di)
static struct demangle_component *
d_template_args (struct d_info *di)
{
+ if (d_peek_char (di) != 'I'
+ && d_peek_char (di) != 'J')
+ return NULL;
+ d_advance (di, 1);
+
+ return d_template_args_1 (di);
+}
+
+/* <template-arg>* E */
+
+static struct demangle_component *
+d_template_args_1 (struct d_info *di)
+{
struct demangle_component *hold_last_name;
struct demangle_component *al;
struct demangle_component **pal;
@@ -3004,11 +3020,6 @@ d_template_args (struct d_info *di)
constructor or destructor. */
hold_last_name = di->last_name;
- if (d_peek_char (di) != 'I'
- && d_peek_char (di) != 'J')
- return NULL;
- d_advance (di, 1);
-
if (d_peek_char (di) == 'E')
{
/* An argument pack can be empty. */
@@ -3270,6 +3281,8 @@ d_expression_1 (struct d_info *di)
if (op->type == DEMANGLE_COMPONENT_CAST
&& d_check_char (di, '_'))
operand = d_exprlist (di, 'E');
+ else if (code && !strcmp (code, "sP"))
+ operand = d_template_args_1 (di);
else
operand = d_expression_1 (di);
@@ -4289,6 +4302,30 @@ d_pack_length (const struct demangle_component *dc)
return count;
}
+/* Returns the number of template args in DC, expanding any pack expansions
+ found there. */
+
+static int
+d_args_length (struct d_print_info *dpi, const struct demangle_component *dc)
+{
+ int count = 0;
+ for (; dc && dc->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST;
+ dc = d_right (dc))
+ {
+ struct demangle_component *elt = d_left (dc);
+ if (elt == NULL)
+ break;
+ if (elt->type == DEMANGLE_COMPONENT_PACK_EXPANSION)
+ {
+ struct demangle_component *a = d_find_pack (dpi, d_left (elt));
+ count += d_pack_length (a);
+ }
+ else
+ ++count;
+ }
+ return count;
+}
+
/* DC is a component of a mangled expression. Print it, wrapped in parens
if needed. */
@@ -5125,6 +5162,21 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
}
}
+ /* For sizeof..., just print the pack length. */
+ if (code && !strcmp (code, "sZ"))
+ {
+ struct demangle_component *a = d_find_pack (dpi, operand);
+ int len = d_pack_length (a);
+ d_append_num (dpi, len);
+ return;
+ }
+ else if (code && !strcmp (code, "sP"))
+ {
+ int len = d_args_length (dpi, operand);
+ d_append_num (dpi, len);
+ return;
+ }
+
if (op->type != DEMANGLE_COMPONENT_CAST)
d_print_expr_op (dpi, options, op);
else
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index 1d959528b97b..92ad01f6e61e 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -4536,6 +4536,12 @@ void baz<int>(A<sizeof (foo((int)(), (floatcomplex )00000000_00000000))>*)
--format=gnu-v3
_Z3fooI1FEN1XIXszdtcl1PclcvT__EEE5arrayEE4TypeEv
X<sizeof ((P(((F)())())).array)>::Type foo<F>()
+
+_Z1fIJidEEv1AIXsZT_EE
+void f<int, double>(A<2>)
+
+_ZN1A1fIJiiEiJiiiEEEvRAsPDpT_T0_DpT1_E_iS3_S5_
+void A::f<int, int, int, int, int, int>(int (&) [6], int, int, int, int)
#
# Tests a use-after-free problem PR70481