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]

C++ PATCH: demangler fix


This patch fixes a subtle bug in new-ABI demangler regarding the
interaction between special substitutions and numbered substitutions.

in libiberty:

	* cp-demangle.c (status_allocation_failed): Rearrange whitespace.
	(demangle_type): Handle substitution candidates correctly in the
	face of special substitutions.



Index: cp-demangle.c
===================================================================
RCS file: /cvs/gcc/egcs/libiberty/cp-demangle.c,v
retrieving revision 1.21
diff -c -p -r1.21 cp-demangle.c
*** cp-demangle.c	2000/09/05 22:37:17	1.21
--- cp-demangle.c	2000/09/06 22:44:59
*************** typedef const char *status_t;
*** 170,176 ****
  #define STATUS_INTERNAL_ERROR           "Internal error."
  
  /* This status code indicates a failure in malloc or realloc.  */
! static const char* const status_allocation_failed = "Allocation failed.";
  #define STATUS_ALLOCATION_FAILED        status_allocation_failed
  
  /* Non-zero if STATUS indicates that no error has occurred.  */
--- 170,176 ----
  #define STATUS_INTERNAL_ERROR           "Internal error."
  
  /* This status code indicates a failure in malloc or realloc.  */
! static const char *const status_allocation_failed = "Allocation failed.";
  #define STATUS_ALLOCATION_FAILED        status_allocation_failed
  
  /* Non-zero if STATUS indicates that no error has occurred.  */
*************** demangle_type (dm)
*** 2284,2293 ****
  	      is_substitution_candidate = 0;
  	  }
  	else
! 	  /* While the special substitution token itself is not a
! 	     substitution candidate, the <class-enum-type> is, so
! 	     don't clear is_substitution_candidate.  */
! 	  RETURN_IF_ERROR (demangle_class_enum_type (dm, &encode_return_type));
  
  	break;
  
--- 2284,2314 ----
  	      is_substitution_candidate = 0;
  	  }
  	else
! 	  {
! 	    /* Now some trickiness.  We have a special substitution
! 	       here.  Often, the special substitution provides the
! 	       name of a template that's subsequently instantiated,
! 	       for instance `SaIcE' => std::allocator<char>.  In these
! 	       cases we need to add a substitution candidate for the
! 	       entire <class-enum-type> and thus don't want to clear
! 	       the is_substitution_candidate flag.
! 
! 	       However, it's possible that what we have here is a
! 	       substitution token representing an entire type, such as
! 	       `Ss' => std::string.  In this case, we mustn't add a
! 	       new substitution candidate for this substitution token.
! 	       To detect this case, remember where the start of the
! 	       substitution token is.  */
!  	    const char *next = dm->next;
! 	    /* Now demangle the <class-enum-type>.  */
! 	    RETURN_IF_ERROR 
! 	      (demangle_class_enum_type (dm, &encode_return_type));
! 	    /* If all that was just demangled is the two-character
! 	       special substitution token, supress the addition of a
! 	       new candidate for it.  */
! 	    if (dm->next == next + 2)
! 	      is_substitution_candidate = 0;
! 	  }
  
  	break;
  

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