public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: jason@redhat.com, iant@google.com
Cc: nickc@redhat.com, GCC Patches <gcc-patches@gcc.gnu.org>,
	binutils@sourceware.org, P@draigBrady.com
Subject: Re: [C++/78252 PATCH] libiberty demangler crash with lambda (auto)
Date: Tue, 06 Dec 2016 12:33:00 -0000	[thread overview]
Message-ID: <4410b360-ee41-55fb-2e32-3afa9f9a827c@acm.org> (raw)
In-Reply-To: <0cacb244-ba7b-c252-9958-3e30cdcea96a@acm.org>

Ping?
https://gcc.gnu.org/ml/gcc-patches/2016-11/msg03102.html

Don't get confused by the chatter on 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70909.  That defect mixes 
demangler recursion due to malformed symbols with recursion on 
well-formed ones.  This patch fixes the well-formed lambda subset of 
that recursion problem.

nathan


On 11/30/2016 02:06 PM, Nathan Sidwell wrote:
> This patch fixes a problem in libiberty's symbol demangler.  With a
> templated forwarding function such as std::forward, we can end up
> emitting mangled function names that encode lambda information.  Lambdas
> with auto argument types have a synthesized templated operator(), and
> g++ uses that when mangling the lambda.
>
> Unfortunately g++ doesn't notice the template parameters there mean
> 'auto' and emits regular template parameter references. (This is a bug,
> see below.)
>
> But, as the forwarding function itself is a template, and the lambda is
> part of a template parameter substitution, we can end up with the
> demangler recursing unboundedly.  In other cases we can fail to demangle
> (returning null), or demangle to an unexpected type (substituting the
> current template parameter type into the place of the 'auto').
>
> This patch fixes the demangler by noting when it's printing the argument
> types of a lambda.  In that case whenever we encounter a template
> parameter reference we emit 'auto', and also inhibit some &/&& smushing
> that needs checking.  AFAICT, once inside a lambda argument list we
> cannot encounter template parameter references that actually refer to an
> enclosing template argument list. That means we don't have the problem
> of disabling this additional check within the argument list printing.  I
> don't think we can meet a nested lambda type either, but the ++...--
> idiom seemed safer to me.
>
> We cannot do this substitution when parsing the mangled name, because
> g++ applies the usual squangling back references as-if there really was
> a template parameter reference.  Later squangling references to the type
> containing the lambda argument may or may not require the reference to
> be to an enclosing template argument, or be auto, depending on the
> context of the squangle reference.
>
> I've also included a c++ testcase to check the mangling of the lambdas
> that cause this.  While this is a g++ bug, it's an ABI-affecting one,
> and we shouldn't change the behaviour unintentionally.  I've not
> investigated why the mangler's failing to check is_auto, and will look
> at that later.  I imagine a fix will be -fabi-version dependent. I have
> filed 78621 to track it.
>
> ok?
>
> Nick, we originally found this when GDB exploded. If you're ok with it,
> I'll commit to binutils/gdb when approved for gcc.
>
> nathan


-- 
Nathan Sidwell

  parent reply	other threads:[~2016-12-06 12:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-30 19:06 [C++/78252] " Nathan Sidwell
2016-12-01  7:53 ` Markus Trippelsdorf
2016-12-06 12:33 ` Nathan Sidwell [this message]
2016-12-12 13:54 ` Nathan Sidwell
2016-12-12 16:53   ` Jason Merrill

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=4410b360-ee41-55fb-2e32-3afa9f9a827c@acm.org \
    --to=nathan@acm.org \
    --cc=P@draigBrady.com \
    --cc=binutils@sourceware.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=iant@google.com \
    --cc=jason@redhat.com \
    --cc=nickc@redhat.com \
    /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).