This is the mail archive of the gcc-patches@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]

C++ PATCH: Mangling bug



I just found this bug (by random chance) this afternoon.

When confronted with an array type whose elements were cv-qualified,
the mangler was getting confused.  We put the cv-qualifiers on the
element type, but the mangler was using cp_type_quals -- which pulls
them up to the top level -- and then infinitely recursing.  Ugh.

In GCC 3.0.x, we compiled this code, but mangled it wrongly.  In
GCC 3.1, we crash.  That makes it a regression, so this patch is 
applied to both the mainline and the branch.

Tested on i686-pc-linux-gnu.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2002-04-24  Mark Mitchell  <mark@codesourcery.com>

	* mangle.c (write_type): Don't use TYPE_MAIN_VARIANT when writing
	out an array type.
	(write_CV_qualifiers_for_type): Use TYPE_QUALS, not cp_type_quals,
	to determine qualifiers.

2002-04-24  Mark Mitchell  <mark@codesourcery.com>

	* g++.dg/abi/mangle7.C: New test.

Index: cp/mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.44.2.3
diff -c -p -r1.44.2.3 mangle.c
*** cp/mangle.c	18 Mar 2002 15:37:35 -0000	1.44.2.3
--- cp/mangle.c	25 Apr 2002 00:57:30 -0000
*************** write_type (type)
*** 1353,1358 ****
--- 1353,1363 ----
         since both the qualified and uqualified types are substitution
         candidates.  */
      write_type (TYPE_MAIN_VARIANT (type));
+   else if (TREE_CODE (type) == ARRAY_TYPE)
+     /* It is important not to use the TYPE_MAIN_VARIANT of TYPE here
+        so that the cv-qualification of the element type is available
+        in write_array_type.  */
+     write_array_type (type);
    else
      {
        /* See through any typedefs.  */
*************** write_type (type)
*** 1399,1408 ****
  	  write_nested_name (TYPE_STUB_DECL (type));
  	  break;
  
- 	case ARRAY_TYPE:
- 	  write_array_type (type);
- 	  break;
- 
  	case POINTER_TYPE:
  	  /* A pointer-to-member variable is represented by a POINTER_TYPE
  	     to an OFFSET_TYPE, so check for this first.  */
--- 1404,1409 ----
*************** write_CV_qualifiers_for_type (type)
*** 1469,1487 ****
  
         "In cases where multiple order-insensitive qualifiers are
         present, they should be ordered 'K' (closest to the base type),
!        'V', 'r', and 'U' (farthest from the base type) ..."  */
  
!   if (CP_TYPE_RESTRICT_P (type))
      {
        write_char ('r');
        ++num_qualifiers;
      }
!   if (CP_TYPE_VOLATILE_P (type))
      {
        write_char ('V');
        ++num_qualifiers;
      }
!   if (CP_TYPE_CONST_P (type))
      {
        write_char ('K');
        ++num_qualifiers;
--- 1470,1492 ----
  
         "In cases where multiple order-insensitive qualifiers are
         present, they should be ordered 'K' (closest to the base type),
!        'V', 'r', and 'U' (farthest from the base type) ..."  
! 
!      Note that we do not use cp_type_quals below; given "const
!      int[3]", the "const" is emitted with the "int", not with the
!      array.  */
  
!   if (TYPE_QUALS (type) & TYPE_QUAL_RESTRICT)
      {
        write_char ('r');
        ++num_qualifiers;
      }
!   if (TYPE_QUALS (type) & TYPE_QUAL_VOLATILE)
      {
        write_char ('V');
        ++num_qualifiers;
      }
!   if (TYPE_QUALS (type) & TYPE_QUAL_CONST)
      {
        write_char ('K');
        ++num_qualifiers;
Index: testsuite/g++.dg/abi/mangle7.C
===================================================================
RCS file: testsuite/g++.dg/abi/mangle7.C
diff -N testsuite/g++.dg/abi/mangle7.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/abi/mangle7.C	25 Apr 2002 00:57:33 -0000
***************
*** 0 ****
--- 1,6 ----
+ /* { dg-do compile } */
+ 
+ typedef void *const t1[2];
+ float const f1(t1 (&)[79], ...) {}
+ 
+ /* { dg-final { scan-assembler _Z2f1RA79_A2_KPvz } } */


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