Bug 43838 - [4.4/4.5/4.6 Regression] Incorrect output from abi::__cxa_demangle
Summary: [4.4/4.5/4.6 Regression] Incorrect output from abi::__cxa_demangle
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 4.4.3
: P3 normal
Target Milestone: 4.4.5
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-21 18:14 UTC by Slawomir Czarko
Modified: 2010-06-14 08:43 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-06-09 18:09:12


Attachments
Preprocessed source of example program (72.99 KB, text/plain)
2010-04-21 18:15 UTC, Slawomir Czarko
Details
simpler example (1.42 KB, text/plain)
2010-06-08 17:55 UTC, Slawomir Czarko
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Slawomir Czarko 2010-04-21 18:14:38 UTC
g++ -v:
Using built-in specs.
Target: i686-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch=i686 --build=i686-redhat-linux
Thread model: posix
gcc version 4.4.3 20100127 (Red Hat 4.4.3-4) (GCC) 


Command line used to compile the example program:
g++ -o main main.cpp

For some template types the output of abi::__cxa_demangle is incorrect.

This was working OK in version 4.3.0

Example program is attached

Expected output (when compiled with gcc version 4.3.0 20080428 (Red Hat 4.3.0-8)):

Mangled name:
N5boost6tuples5tupleIN5abcde5xyzzz3abc4abcd3AaaENS5_4klmn16BaaaaaaaaaaaaaaaENS0_9null_typeES9_S9_S9_S9_S9_S9_S9_EE

Demangled name:

boost::tuples::tuple<abcde::xyzzz::abc::abcd::Aaa, abcde::xyzzz::abc::abcd::klmn::Baaaaaaaaaaaaaaa, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>




Actual output (when compiled with gcc version 4.4.3 20100127 (Red Hat 4.4.3-4)):

Mangled name:
N5boost6tuples5tupleIN5abcde5xyzzz3abc4abcd3AaaENS5_4klmn16BaaaaaaaaaaaaaaaENS0_9null_typeES9_S9_S9_S9_S9_S9_S9_EE

Demangled name:

boost::tuples::tuple<abcde::xyzzz::abc::abcd::Aaa, abcde::xyzzz::abc::abcd::klmn::Baaaaaaaaaaaaaaa, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_ty>


As you can see the last occurrence of "null_type" gets truncated to "null_ty".
The mangled name is the same for both compiler versions.

Note that after making some of the namespace or class names shorter the output is correct.
Comment 1 Slawomir Czarko 2010-04-21 18:15:40 UTC
Created attachment 20456 [details]
Preprocessed source of example program
Comment 2 Paolo Carlini 2010-05-24 21:47:11 UTC
Can you please provide a shorter, self-contained (no includes), testcase? Thanks in advance. CC-ing Ian...
Comment 3 Slawomir Czarko 2010-06-08 17:55:14 UTC
Created attachment 20869 [details]
simpler example

Preprocessed source of simpler program.
The only #include used was <typeinfo> which is needed in order to compile with g++
Comment 4 Paolo Carlini 2010-06-08 17:57:00 UTC
Excellent, thanks a lot.
Comment 5 Paolo Carlini 2010-06-08 18:02:33 UTC
I also double checked that indeed the last "null_type" appears truncated.
Comment 6 Paolo Carlini 2010-06-08 18:05:48 UTC
Ian, any idea what may be happening here?
Comment 7 Paolo Carlini 2010-06-09 08:54:59 UTC
Non pre-processed testcase. Apparently some buffer is overflowed.

#include <cxxabi.h>

namespace abcdefgxyzzzaaaaabbbbbb
{
  class Aaa { };

  namespace klmn
  {
    class Baaaaaaaaaaaaaaa { };
  }
}

namespace boost
{
  namespace tuples
  {

    class null_type;

    template<typename T1 = null_type, typename T2 = null_type,
	     typename T3 = null_type, typename T4 = null_type,
	     typename T5 = null_type, typename T6 = null_type,
	     typename T7 = null_type, typename T8 = null_type,
	     typename T9 = null_type, typename T10 = null_type>
      struct tuple { };
  }
}

int main()
{
  int status = 0;

  const char* mangled_name
    = typeid(boost::tuples::tuple<abcdefgxyzzzaaaaabbbbbb::Aaa,
	     abcdefgxyzzzaaaaabbbbbb::klmn::Baaaaaaaaaaaaaaa>).name();

  __builtin_printf("Mangled name:\n%s\n\n", mangled_name);

  const char* dem_name = abi::__cxa_demangle(mangled_name, 0, 0, &status);

  if (0 == status)
    __builtin_printf("Demangled name:\n\n%s\n\n", dem_name);

  return 0;
}
Comment 8 Paolo Carlini 2010-06-09 09:37:35 UTC
Recategorizing as other (like 42230)... and maybe HJ is interested in playing a bit with this one too.
Comment 9 H.J. Lu 2010-06-09 16:56:44 UTC
It is caused by revision 142799:

http://gcc.gnu.org/ml/gcc-cvs/2008-12/msg00498.html
Comment 10 Paolo Carlini 2010-06-09 17:05:51 UTC
Thanks HJ.
Comment 11 Jakub Jelinek 2010-06-09 17:24:05 UTC
Can be reproduced also with
c++filt _ZN5boost6tuples5tupleIN23abcdefgxyzzzaaaaabbbbbb3AaaENS2_4klmn16BaaaaaaaaaaaaaaaENS0_9null_typeES6_S6_S6_S6_S6_S6_S6_EE
Comment 12 Jakub Jelinek 2010-06-09 18:09:12 UTC
I see the bug.
Comment 13 Jakub Jelinek 2010-06-10 15:16:02 UTC
Subject: Bug 43838

Author: jakub
Date: Thu Jun 10 15:15:18 2010
New Revision: 160554

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160554
Log:
	PR other/43838
	* cp-demangle.c (struct d_print_info): Add flush_count field.
	(d_print_init): Initialize it to 0.
	(d_print_flush): Increment it.
	(d_print_comp): If needed flush before appending ", ".  Only
	decrement dpi->len if no flushes happened during the recursive
	call.
	* testsuite/demangle-expected: Add a test for this.

Modified:
    trunk/libiberty/ChangeLog
    trunk/libiberty/cp-demangle.c
    trunk/libiberty/testsuite/demangle-expected

Comment 14 Jakub Jelinek 2010-06-10 15:24:32 UTC
Subject: Bug 43838

Author: jakub
Date: Thu Jun 10 15:24:11 2010
New Revision: 160555

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160555
Log:
	PR other/43838
	* cp-demangle.c (struct d_print_info): Add flush_count field.
	(d_print_init): Initialize it to 0.
	(d_print_flush): Increment it.
	(d_print_comp): If needed flush before appending ", ".  Only
	decrement dpi->len if no flushes happened during the recursive
	call.
	* testsuite/demangle-expected: Add a test for this.

Modified:
    branches/gcc-4_5-branch/libiberty/ChangeLog
    branches/gcc-4_5-branch/libiberty/cp-demangle.c
    branches/gcc-4_5-branch/libiberty/testsuite/demangle-expected

Comment 15 Jakub Jelinek 2010-06-10 15:32:36 UTC
Subject: Bug 43838

Author: jakub
Date: Thu Jun 10 15:31:56 2010
New Revision: 160556

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160556
Log:
	PR other/43838
	* cp-demangle.c (struct d_print_info): Add flush_count field.
	(d_print_init): Initialize it to 0.
	(d_print_flush): Increment it.
	(d_print_comp): If needed flush before appending ", ".  Only
	decrement dpi->len if no flushes happened during the recursive
	call.
	* testsuite/demangle-expected: Add a test for this.

2009-06-16  Nick Clifton  <nickc@redhat.com>

	PR 10197
	* testsuite/test-demangle.c: Rename getline to get_line to avoid
	conflicts with system function of the same name.

Modified:
    branches/gcc-4_4-branch/libiberty/ChangeLog
    branches/gcc-4_4-branch/libiberty/cp-demangle.c
    branches/gcc-4_4-branch/libiberty/testsuite/demangle-expected
    branches/gcc-4_4-branch/libiberty/testsuite/test-demangle.c

Comment 16 Jakub Jelinek 2010-06-14 08:43:35 UTC
Fixed.