Go to file
Pedro Alves 921da19854 PR other/61321 - demangler crash on casts in template parameters
The fix for bug 59195:

 [C++ demangler handles conversion operator incorrectly]
 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59195

unfortunately makes the demangler crash due to infinite recursion, in
case of casts in template parameters.

For example, with:

 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 above 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 the fix for 59195, due to:

 static void
 d_print_cast (struct d_print_info *dpi, int options,
	       const struct demangle_component *dc)
 {
 ...
   /* For a cast operator, we need the template parameters from
      the enclosing template in scope for processing the type.  */
   if (dpi->current_template != NULL)
     {
       dpt.next = dpi->templates;
       dpi->templates = &dpt;
       dpt.template_decl = dpi->current_template;
     }

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

Where it reads "for the cast operator" in the comment in d_print_cast
(above), it's really talking about a conversion operator, like:

  struct A { template <typename U> explicit operator U(); };

We don't want to inject the template parameters from the enclosing
template in scope when processing a cast _expression_, only when
handling a conversion operator.

The problem is that DEMANGLE_COMPONENT_CAST is currently ambiguous,
and means _both_ 'conversion operator' and 'cast expression'.

Fix this by adding a new DEMANGLE_COMPONENT_CONVERSION component type,
which does what DEMANGLE_COMPONENT_CAST does today, and making
DEMANGLE_COMPONENT_CAST just simply print its component subtree.

I think we could instead reuse DEMANGLE_COMPONENT_CAST and in
d_print_comp_inner still do:

 @@ -5001,9 +5013,9 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
        d_print_comp (dpi, options, dc->u.s_extended_operator.name);
        return;

     case DEMANGLE_COMPONENT_CAST:
       d_append_string (dpi, "operator ");
 -     d_print_cast (dpi, options, dc);
 +     d_print_conversion (dpi, options, dc);
       return;

leaving the unary cast case below calling d_print_cast, but seems to
me that spliting the component types makes it easier to reason about
the code.

g++'s testsuite actually generates three symbols that crash the
demangler in the same way.  I've added those as tests in the demangler
testsuite as well.

And then this fixes PR other/61233 too, which happens to be a
demangler crash originally reported to GDB, at:
https://sourceware.org/bugzilla/show_bug.cgi?id=16957

Bootstrapped and regtested on x86_64 Fedora 20.

Also ran this through GDB's testsuite.  GDB will require a small
update to use DEMANGLE_COMPONENT_CONVERSION in one place it's using
DEMANGLE_COMPONENT_CAST in its sources.

libiberty/
2015-11-27  Pedro Alves  <palves@redhat.com>

        PR other/61321
        PR other/61233
        * demangle.h (enum demangle_component_type)
        <DEMANGLE_COMPONENT_CONVERSION>: New value.
        * cp-demangle.c (d_demangle_callback, d_make_comp): Handle
        DEMANGLE_COMPONENT_CONVERSION.
        (is_ctor_dtor_or_conversion): Handle DEMANGLE_COMPONENT_CONVERSION
        instead of DEMANGLE_COMPONENT_CAST.
        (d_operator_name): Return a DEMANGLE_COMPONENT_CONVERSION
        component if handling a conversion.
        (d_count_templates_scopes, d_print_comp_inner): Handle
        DEMANGLE_COMPONENT_CONVERSION.
        (d_print_comp_inner): Handle DEMANGLE_COMPONENT_CONVERSION instead
        of DEMANGLE_COMPONENT_CAST.
        (d_print_cast): Rename as ...
        (d_print_conversion): ... this.  Adjust comments.
        (d_print_cast): Rewrite - simply print the left subcomponent.
        * cp-demint.c (cplus_demangle_fill_component): Handle
        DEMANGLE_COMPONENT_CONVERSION.

        * testsuite/demangle-expected: Add tests.

From-SVN: r231020
2015-11-27 14:48:21 +00:00
boehm-gc Testsuite: add dg-{begin|end}-multiline-output commands 2015-10-09 13:55:23 +00:00
config libsanitizer merge from upstream r250806, compiler part. 2015-10-21 10:40:54 +03:00
contrib clang-format: split content of a list to multiple lines 2015-11-20 12:24:34 +00:00
fixincludes inclhack.def (aix_stdio_inline): New fix. 2015-08-14 07:17:29 -04:00
gcc Fix FAIL: gcc.c-torture/execute/20050124-1.c -O2 (internal compiler error) 2015-11-27 14:39:34 +00:00
gnattools configure.ac (*-*-dragonfly*): New configuration. 2015-06-08 07:27:56 +00:00
gotools Makefile.am (go_cmd_go_files): Update to Go 1.5.1 library by adding alldocs.go, doc.go, note.go. 2015-10-31 21:29:38 +00:00
include PR other/61321 - demangler crash on casts in template parameters 2015-11-27 14:48:21 +00:00
INSTALL README: Do not mention CVS. 2014-10-12 15:05:28 +00:00
intl Makefile.def (libiconv): Define bootstrap=true. 2015-08-07 01:13:52 -04:00
libada re PR target/65351 (libiberty's pic version contains non-pic code on m32 darwin; causes bootstrap fail building libcc1.) 2015-04-10 06:43:52 +00:00
libatomic Add out-of-line versions of some <stdatomic.h> functions (PR c/65083). 2015-11-18 22:13:44 +00:00
libbacktrace posix.c (backtrace_open): Cast second argument of open() to int. 2015-09-17 13:08:04 -04:00
libcc1 hash-traits.h (free_ptr_hash): New class. 2015-06-25 17:06:24 +00:00
libcilkrts re PR target/66326 (Floating point exception with -mfpmath=387 and -fcilkplus.) 2015-11-09 10:12:34 +00:00
libcpp PR 62314: add ability to add fixit-hints to a diagnostic 2015-11-20 20:08:47 +00:00
libdecnumber IA MCU psABI support: changes to libraries 2015-06-30 09:42:07 -07:00
libffi re PR libffi/65441 (FAIL: libffi.call/float2.c -W -Wall -Wno-psabi (test for excess errors)) 2015-10-27 00:39:32 +00:00
libgcc Port libvtv to Solaris 2015-11-25 10:30:25 +00:00
libgfortran re PR fortran/52251 (Nonadvancing I/O and the t edit descriptor) 2015-11-23 00:40:51 +00:00
libgo re PR go/61303 (gccgo: segfault, regression since 4.8.2) 2015-11-26 00:24:21 +00:00
libgomp re PR c/63326 (whether a #pragma is a statement depends on the type of pragma) 2015-11-27 09:59:55 +01:00
libiberty PR other/61321 - demangler crash on casts in template parameters 2015-11-27 14:48:21 +00:00
libitm libitm: Use multiplicative hashing in the multi-lock TM method. 2015-11-26 16:10:54 +00:00
libjava libjava: fix locale handling when sorting JNI methods 2015-10-26 18:32:41 +00:00
libmpx re PR other/66887 (trunk/libmpx/mpxrt/mpxrt.c:158: possible performance problem) 2015-10-15 09:26:39 +00:00
libobjc replace BITS_PER_UNIT with __CHAR_BIT__ in target libs 2015-11-07 19:36:26 +00:00
liboffloadmic libgomp-plugin-intelmic.cpp (struct TargetImageDesc): New. 2015-11-19 16:22:13 +00:00
libquadmath Makefile.am (libquadmath_la_SOURCES): Add math/logbq.c. 2015-08-09 08:46:52 +00:00
libsanitizer Move ptrace.h to appropriate place. 2015-11-24 14:24:46 +02:00
libssp libssp: Bump to automake 1.11.6 2015-05-13 11:12:39 +00:00
libstdc++-v3 Ensure another pretty-printer test uses C++98 mode 2015-11-26 16:25:55 +00:00
libvtv Port libvtv to Solaris 2015-11-25 10:30:25 +00:00
lto-plugin re PR lto/67548 (LTO drops weak binding with "ld -r") 2015-11-25 23:05:07 +00:00
maintainer-scripts update_version_svn: Add gcc-4_8-branch to IGNORE_BRANCHES. 2015-06-23 07:48:06 +00:00
zlib 2015-11-23 Matthias Klose <doko@ubuntu.com> 2015-11-23 20:27:57 +00:00
.dir-locals.el
.gitignore Add clang-format config to contrib folder 2015-11-19 12:32:09 +00:00
ABOUT-NLS
ChangeLog * libtool.m4 (export_symbols_cmds) [AIX]: Add global TLS "L" symbols. 2015-11-26 08:20:59 -05:00
ChangeLog.jit Merger of dmalcolm/jit branch from git 2014-11-11 21:55:52 +00:00
ChangeLog.tree-ssa
compile Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
config-ml.in re PR other/66259 (Combined gcc and binutils build from git-master fails, with gas/as-new not existing) 2015-07-24 12:20:44 -06:00
config.guess * config.sub, config.guess: Import from upstream. 2015-07-28 10:57:40 +10:00
config.rpath
config.sub * config.sub, config.guess: Import from upstream. 2015-07-28 10:57:40 +10:00
configure Sync top level configure with binutils-gdb. 2015-11-20 14:24:07 +00:00
configure.ac Sync top level configure with binutils-gdb. 2015-11-20 14:24:07 +00:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
install-sh Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
libtool-ldflags re PR sanitizer/56781 (boostrap-asan failure: fixincl fails to link (missing -lasan)) 2014-04-17 14:23:28 +02:00
libtool.m4 * libtool.m4 (export_symbols_cmds) [AIX]: Add global TLS "L" symbols. 2015-11-26 08:20:59 -05:00
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Update email address. 2015-10-23 17:06:07 +00:00
Makefile.def re PR libfortran/54572 (Use libbacktrace library) 2015-08-23 21:50:30 +00:00
Makefile.in Add clang-format config to contrib folder 2015-11-19 12:32:09 +00:00
Makefile.tpl Add clang-format config to contrib folder 2015-11-19 12:32:09 +00:00
missing Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
mkdep
mkinstalldirs Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
move-if-change Update move-if-change from gnulib 2014-11-16 16:12:44 +00:00
README
symlink-tree
ylwrap Update from upstream Automake files. 2014-11-16 14:07:13 +00:00

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.