From: Nathan Sidwell Date: Fri, 15 Sep 2017 12:23:57 +0000 (+0000) Subject: [demangler] Fix nested generic lambda X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fa0cdfb651f59951d10331b782c422baad93d3e4;p=gcc.git [demangler] Fix nested generic lambda https://gcc.gnu.org/ml/gcc-patches/2017-09/msg00994.html PR demangler/82195 * cp-demangle.c (d_name): Add 'toplevel' parm. Pass to ... (d_local_name): ... here. Parse trailing function args on nested local_name. (d_encoding, d_special_name, d_class_enum_type): Adjust d_name calls. * testsuite/demangle-expected: Add tests. From-SVN: r252815 --- diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 65c521ca14a..7a49a6a1397 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,12 @@ +2017-09-15 Nathan Sidwell + + PR demangler/82195 + * cp-demangle.c (d_name): Add 'toplevel' parm. Pass to ... + (d_local_name): ... here. Parse trailing function args on nested + local_name. + (d_encoding, d_special_name, d_class_enum_type): Adjust d_name calls. + * testsuite/demangle-expected: Add tests. + 2017-09-15 Richard Biener PR lto/81968 @@ -11,6 +20,8 @@ (d_encoding): Hold bare_function_type in local var. (d_local_name): Build name in both cases and build result once. Collapse switch-if to single conditional. + (d_local_name): + * testsuite/demangle-expected: Realign blank lines with tests. 2017-09-12 Jiong Wang diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index e8705984c52..c3300528ff0 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -425,7 +425,7 @@ is_ctor_dtor_or_conversion (struct demangle_component *); static struct demangle_component *d_encoding (struct d_info *, int); -static struct demangle_component *d_name (struct d_info *); +static struct demangle_component *d_name (struct d_info *, int); static struct demangle_component *d_nested_name (struct d_info *); @@ -484,7 +484,7 @@ static struct demangle_component *d_expression (struct d_info *); static struct demangle_component *d_expr_primary (struct d_info *); -static struct demangle_component *d_local_name (struct d_info *); +static struct demangle_component *d_local_name (struct d_info *, int); static int d_discriminator (struct d_info *); @@ -1308,7 +1308,7 @@ d_encoding (struct d_info *di, int top_level) { struct demangle_component *dc, *dcr; - dc = d_name (di); + dc = d_name (di, top_level); if (dc != NULL && top_level && (di->options & DMGL_PARAMS) == 0) { @@ -1383,7 +1383,7 @@ d_abi_tags (struct d_info *di, struct demangle_component *dc) */ static struct demangle_component * -d_name (struct d_info *di) +d_name (struct d_info *di, int top_level) { char peek = d_peek_char (di); struct demangle_component *dc; @@ -1394,7 +1394,7 @@ d_name (struct d_info *di) return d_nested_name (di); case 'Z': - return d_local_name (di); + return d_local_name (di, top_level); case 'U': return d_unqualified_name (di); @@ -2079,11 +2079,11 @@ d_special_name (struct d_info *di) case 'H': return d_make_comp (di, DEMANGLE_COMPONENT_TLS_INIT, - d_name (di), NULL); + d_name (di, 0), NULL); case 'W': return d_make_comp (di, DEMANGLE_COMPONENT_TLS_WRAPPER, - d_name (di), NULL); + d_name (di, 0), NULL); default: return NULL; @@ -2094,11 +2094,12 @@ d_special_name (struct d_info *di) switch (d_next_char (di)) { case 'V': - return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, d_name (di), NULL); + return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, + d_name (di, 0), NULL); case 'R': { - struct demangle_component *name = d_name (di); + struct demangle_component *name = d_name (di, 0); return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, name, d_number_component (di)); } @@ -2934,7 +2935,7 @@ d_bare_function_type (struct d_info *di, int has_return_type) static struct demangle_component * d_class_enum_type (struct d_info *di) { - return d_name (di); + return d_name (di, 0); } /* ::= A <(positive dimension) number> _ <(element) type> @@ -3567,7 +3568,7 @@ d_expr_primary (struct d_info *di) */ static struct demangle_component * -d_local_name (struct d_info *di) +d_local_name (struct d_info *di, int top_level) { struct demangle_component *function; struct demangle_component *name; @@ -3600,14 +3601,30 @@ d_local_name (struct d_info *di) return NULL; } - name = d_name (di); + name = d_name (di, 0); + if (name - /* Lambdas and unnamed types have internal discriminators. */ + /* Lambdas and unnamed types have internal discriminators + and are not functions. */ && name->type != DEMANGLE_COMPONENT_LAMBDA - && name->type != DEMANGLE_COMPONENT_UNNAMED_TYPE - /* Otherwise read and ignore an optional discriminator. */ - && ! d_discriminator (di)) - return NULL; + && name->type != DEMANGLE_COMPONENT_UNNAMED_TYPE) + { + if (!top_level + && d_peek_char (di) != 0 /* Not end of string. */ + && d_peek_char (di) != 'E' /* Not end of nested encoding. */ + && d_peek_char (di) != '_') /* Not discriminator. */ + { + struct demangle_component *args; + + args = d_bare_function_type (di, has_return_type (name)); + name = d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME, + name, args); + } + + /* Read and ignore an optional discriminator. */ + if (! d_discriminator (di)) + return NULL; + } if (num >= 0) name = d_make_default_arg (di, num, name); diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index 519f6d05f27..c1a9a73f4df 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -4736,3 +4736,17 @@ __thunk_16a_$_1x __thunk_4294967297__$_1x __thunk_4294967297__$_1x # +# demangler/82195 members of lambdas +--no-params +_ZZZ3FoovENKUlT_E_clIiEEfS_EN5Local2fnEv +Foo()::float {lambda(auto:1)#1}::operator()(int) const::Local::fn() +Foo()::float {lambda(auto:1)#1}::operator()(int) const::Local::fn +--no-params +_Z7CaptureIZZ3FoovENKUlT_E_clIiEEvS0_EUlvE_EvOS0_ +void Capture(int) const::{lambda()#1}>(Foo()::void {lambda(auto:1)#1}::operator()(int) const::{lambda()#1}&&) +Capture(int) const::{lambda()#1}> +--no-params +_Z4FrobIZZ3FoovENKUlT_E_clIiEEvS0_EUlvE_Evv +void Frob(int) const::{lambda()#1}>() +Frob(int) const::{lambda()#1}> +#