From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1059) id 71DBD3857809; Fri, 7 Oct 2022 16:12:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71DBD3857809 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665159147; bh=QN10V9R00w3/w9lsdYv/xwbhJuRk4hZ1dPbUzQLtU9g=; h=From:To:Subject:Date:From; b=Y9wtgzqVYcSeg0HpJp+nEG0QgYmSj6CId0fiFho4OMk29qbPIz6Qo3o6k4HYDVDog 558IqxtuQEQQex6XkpqhoerxqxK+QajD7p3oigGqyBLxHSU0nk5ATsGHlbRc+qZ+7z EXLMtwzGCJ+uBDeEAVVl0x5ueLsYWIR4jzc0qGp4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Nathan Sidwell To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3167] libiberty: Demangle variadic template lambdas X-Act-Checkin: gcc X-Git-Author: Nathan Sidwell X-Git-Refname: refs/heads/master X-Git-Oldrev: f7f4628054358a92a55d52645cf107aa26ff6765 X-Git-Newrev: eb491ea5c10955c667ceeda76dede393c93a377b Message-Id: <20221007161227.71DBD3857809@sourceware.org> Date: Fri, 7 Oct 2022 16:12:27 +0000 (GMT) List-Id: https://gcc.gnu.org/g:eb491ea5c10955c667ceeda76dede393c93a377b commit r13-3167-geb491ea5c10955c667ceeda76dede393c93a377b Author: Nathan Sidwell Date: Fri Sep 30 12:11:42 2022 -0700 libiberty: Demangle variadic template lambdas Now we have templated lambdas, we can have variadic template lambdas, and this leads to lambda signatures containing parameter packs. But just like 'auto' inside such a signature, we don't have a containing template, and thus fail. The fix is to check is_lambda_arg, just as for a template parameter. This allows us to demangle g++'s manglings of such lambdas. It's not a totally accurate demangling, because we don't mangle the template head (that's a separate issue), but it is better than failing to demangle. Due to the way we print subexprs, we add an unnecessary parens around the argument of the pack. That's an orthogonal problem, for which the solution is to have better knowledge of operator precedence. libiberty/ * cp-demangle.c (d_print_comp_inner): Allow parameter packs in a lambda signature. * testsuite/demangle-expected: Add tests. Diff: --- libiberty/cp-demangle.c | 30 +++++++++++++++++------------- libiberty/testsuite/demangle-expected | 7 +++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 7ff225ec1aa..303bfbf709e 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -348,7 +348,7 @@ struct d_print_info be bigger than MAX_RECURSION_COUNT. */ int recursion; /* Non-zero if we're printing a lambda argument. A template - parameter reference actually means 'auto'. */ + parameter reference actually means 'auto', a pack expansion means T... */ int is_lambda_arg; /* The current index into any template argument packs we are using for printing, or -1 to print the whole pack. */ @@ -5930,9 +5930,10 @@ d_print_comp_inner (struct d_print_info *dpi, int options, case DEMANGLE_COMPONENT_PACK_EXPANSION: { - int len; - int i; - struct demangle_component *a = d_find_pack (dpi, d_left (dc)); + struct demangle_component *a = NULL; + + if (!dpi->is_lambda_arg) + a = d_find_pack (dpi, d_left (dc)); if (a == NULL) { /* d_find_pack won't find anything if the only packs involved @@ -5940,17 +5941,20 @@ d_print_comp_inner (struct d_print_info *dpi, int options, case, just print the pattern and "...". */ d_print_subexpr (dpi, options, d_left (dc)); d_append_string (dpi, "..."); - return; } - - len = d_pack_length (a); - dc = d_left (dc); - for (i = 0; i < len; ++i) + else { - dpi->pack_index = i; - d_print_comp (dpi, options, dc); - if (i < len-1) - d_append_string (dpi, ", "); + int len = d_pack_length (a); + int i; + + dc = d_left (dc); + for (i = 0; i < len; ++i) + { + if (i) + d_append_string (dpi, ", "); + dpi->pack_index = i; + d_print_comp (dpi, options, dc); + } } } return; diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index 8fad6893ae7..90dd4a13945 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -1574,3 +1574,10 @@ initializer for module Foo.Bar _ZGIW3FooWP3BarW3Baz initializer for module Foo:Bar.Baz + +_ZZ2L1vENKUlDpT_E_clIJiPiEEEvS0_ +void L1()::{lambda((auto:1)...)#1}::operator()(int, int*) const + +_ZZ2L1vENKUlDpT_E_clIJiPiEEEDaS0_ +auto L1()::{lambda((auto:1)...)#1}::operator()(int, int*) const +