public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10734] c++: mangling of lambdas in default args [PR91241]
Date: Fri, 13 May 2022 17:13:55 +0000 (GMT)	[thread overview]
Message-ID: <20220513171355.0B738395B06C@sourceware.org> (raw)

https://gcc.gnu.org/g:a86e0cadefe5a2469bb9872bb5b93017ccb23935

commit r10-10734-ga86e0cadefe5a2469bb9872bb5b93017ccb23935
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Apr 5 22:50:44 2021 -0400

    c++: mangling of lambdas in default args [PR91241]
    
    In this testcase, the parms remembered in LAMBDA_EXPR_EXTRA_SCOPE are no
    longer the parms of the FUNCTION_DECL they have as their DECL_CONTEXT, so we
    were mangling both lambdas as parm #0.  But since the parms are numbered
    from right to left we don't need to need to find them in the FUNCTION_DECL,
    we can measure their own DECL_CHAIN.
    
    gcc/cp/ChangeLog:
    
            PR c++/91241
            * mangle.c (write_compact_number): Add sanity check.
            (write_local_name): Use list_length for parm number.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/91241
            * g++.dg/abi/lambda-defarg1.C: New test.

Diff:
---
 gcc/cp/mangle.c                           | 11 ++---------
 gcc/testsuite/g++.dg/abi/lambda-defarg1.C | 11 +++++++++++
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index cd2fdd91537..d0682e5b93a 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -1604,6 +1604,7 @@ write_literal_operator_name (tree identifier)
 static void
 write_compact_number (int num)
 {
+  gcc_checking_assert (num >= 0);
   if (num > 0)
     write_unsigned_number (num - 1);
   write_char ('_');
@@ -2003,15 +2004,7 @@ write_local_name (tree function, const tree local_entity,
   /* For this purpose, parameters are numbered from right-to-left.  */
   if (parm)
     {
-      tree t;
-      int i = 0;
-      for (t = DECL_ARGUMENTS (function); t; t = DECL_CHAIN (t))
-	{
-	  if (t == parm)
-	    i = 1;
-	  else if (i)
-	    ++i;
-	}
+      int i = list_length (parm);
       write_char ('d');
       write_compact_number (i - 1);
     }
diff --git a/gcc/testsuite/g++.dg/abi/lambda-defarg1.C b/gcc/testsuite/g++.dg/abi/lambda-defarg1.C
new file mode 100644
index 00000000000..8c538581240
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/lambda-defarg1.C
@@ -0,0 +1,11 @@
+// PR c++/91241
+// { dg-do compile { target c++11 } }
+
+struct A {
+  int *b(const int & = []() -> int { return 0; }(),
+	 const int & = []() -> int { return 0; }());
+};
+int *A::b(const int &, const int &) { b(); return 0; }
+// { dg-final { scan-assembler "_ZN1A1bERKiS1_" } }
+// { dg-final { scan-assembler "_ZZN1A1bERKiS1_Ed_NKUlvE_clEv" } }
+// { dg-final { scan-assembler "_ZZN1A1bERKiS1_Ed0_NKUlvE_clEv" } }


                 reply	other threads:[~2022-05-13 17:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220513171355.0B738395B06C@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).