This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR c++/16240


Ian Lance Taylor wrote:

Mark, I would like to draw your attention to PR c++/16240, as I think
it is a bug in the way in which g++ implements the C++ mangling ABI.

It showed up initially as a demangler bug, in that the demangler was
crashing on an error condition.  I've fixed the demangler to exit
cleanly rather than crash.  However, I believe that the name is
incorrectly mangled, which leaves us with an ABI problem.

I would be happy to hear otherwise.

Thanks for bringing this to my attention.

Rats, and I was just starting to hope we'd not have to have an ABI Version 3.

I think you're completely correct.

I checked in the attached patch, which will fix it with -fabi-version=3, but does not change the default (-fabi-version=2). In practice, other than demangling, it's very unlikely that people will see a symbol clash with -fabi-version=2, so I don't think I'd argue that we ought to make -fabi-version=3 the default because of this bug.

Patch attached; tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
(916) 791-8304
mark@codesourcery.com

2004-07-02  Mark Mitchell  <mark@codesourcery.com>

	PR c++/16240
	* mangle.c (write_template_arg): Correct mangling.

2004-07-02  Mark Mitchell  <mark@codesourcery.com>

	PR c++/16240
	* g++.dg/abi/mangle22.C: New test.
	* g++.dg/abi/mangle23.C: Likewise.

Index: cp/mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.101
diff -c -5 -p -r1.101 mangle.c
*** cp/mangle.c	1 Apr 2004 03:50:39 -0000	1.101
--- cp/mangle.c	2 Jul 2004 23:51:16 -0000
*************** write_template_arg (tree node)
*** 2201,2216 ****
    else if ((TREE_CODE_CLASS (code) == 'c' && code != PTRMEM_CST)
  	   || (abi_version_at_least (2) && code == CONST_DECL))
      write_template_arg_literal (node);
    else if (DECL_P (node))
      {
!       /* G++ 3.2 incorrectly mangled non-type template arguments of
! 	 enumeration type using their names.  */
!       if (code == CONST_DECL)
  	G.need_abi_warning = 1;
        write_char ('L');
!       write_char ('Z');
        write_encoding (node);
        write_char ('E');
      }
    else
      {
--- 2201,2224 ----
    else if ((TREE_CODE_CLASS (code) == 'c' && code != PTRMEM_CST)
  	   || (abi_version_at_least (2) && code == CONST_DECL))
      write_template_arg_literal (node);
    else if (DECL_P (node))
      {
!       /* Until ABI version 2, non-type template arguments of
! 	 enumeration type were mangled using their names.  */ 
!       if (code == CONST_DECL && !abi_version_at_least (2))
  	G.need_abi_warning = 1;
        write_char ('L');
!       /* Until ABI version 3, the underscore before the mangled name
! 	 was incorrectly omitted.  */
!       if (!abi_version_at_least (3))
! 	{
! 	  G.need_abi_warning = 1;
! 	  write_char ('Z');
! 	}
!       else
! 	write_string ("_Z");
        write_encoding (node);
        write_char ('E');
      }
    else
      {
Index: testsuite/g++.dg/abi/mangle22.C
===================================================================
RCS file: testsuite/g++.dg/abi/mangle22.C
diff -N testsuite/g++.dg/abi/mangle22.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/abi/mangle22.C	2 Jul 2004 23:51:17 -0000
***************
*** 0 ****
--- 1,9 ----
+ // PR c++/16240
+ // { dg-options "-fabi-version=3" }
+ 
+ void foo(char);
+ template<void (&)(char)> struct CB {};
+ 
+ void g(CB<foo> i) {}
+ 
+ // { dg-final { scan-assembler "\n_?_Z1g2CBIL_Z3foocEE\[: \t\n\]" } }
Index: testsuite/g++.dg/abi/mangle23.C
===================================================================
RCS file: testsuite/g++.dg/abi/mangle23.C
diff -N testsuite/g++.dg/abi/mangle23.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/abi/mangle23.C	2 Jul 2004 23:51:17 -0000
***************
*** 0 ****
--- 1,9 ----
+ // PR c++/16240
+ // { dg-options "-fabi-version=2" }
+ 
+ void foo(char);
+ template<void (&)(char)> struct CB {};
+ 
+ void g(CB<foo> i) {}
+ 
+ // { dg-final { scan-assembler "\n_?_Z1g2CBILZ3foocEE\[: \t\n\]" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]