public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "palves at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug other/61321] New: demangler crash on casts in template parameters
Date: Mon, 26 May 2014 14:03:00 -0000	[thread overview]
Message-ID: <bug-61321-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61321

            Bug ID: 61321
           Summary: demangler crash on casts in template parameters
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: palves at redhat dot com

The fix for bug 59195 (C++ demangler handles conversion operator incorrectly)
makes the demangler crash crash due to infinite recursion, in case of casts in
template parameters.  For example:

 template<int> struct A {};
 template <typename Y> void function_temp(A<sizeof ((Y)(999))>) {}
 template void function_temp<int>(A<sizeof (int)>);

The function_temp<int> instantiation  mangles to:
  _Z13function_tempIiEv1AIXszcvT_Li999EEE

The demangler parses this as:

typed name
  template
    name 'function_temp'
    template argument list
      builtin type int
  function type
    builtin type void
    argument list
      template
        name 'A'
        template argument list
          unary operator
            operator sizeof 
            unary operator
              cast
                template parameter 0
              literal
                builtin type int
                name '999'

And after this patch, when printing the template argument list of A (what
should be "<sizeof (int)>"), the template parameter 0 (that is, "T_") now
refers to the first parameter of the the template argument list of the 'A'
template, exactly what we were trying to print, while it should actually refer
to the first parameter of the 'function_temp' template.  This leads to infinite
recursion, and stack exaustion.

(This is particularly nasty for GDB, as it causes an immediate crash at
startup.)


             reply	other threads:[~2014-05-26 14:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-26 14:03 palves at redhat dot com [this message]
2014-05-26 15:33 ` [Bug other/61321] " palves at redhat dot com
2014-05-26 16:40 ` palves at redhat dot com
2014-05-26 20:52 ` redi at gcc dot gnu.org
2014-05-27 12:00 ` palves at redhat dot com
2014-11-10 19:01 ` ccoutant at gcc dot gnu.org
2014-11-10 19:19 ` ccoutant at gcc dot gnu.org
2015-07-06  4:56 ` trippels at gcc dot gnu.org
2015-07-06  5:14 ` trippels at gcc dot gnu.org
2015-07-14  9:39 ` palves at redhat dot com
2015-07-27 10:09 ` trippels at gcc dot gnu.org
2015-08-18 23:11 ` miyuki at gcc dot gnu.org

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=bug-61321-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).