CFA: fix for demangler bug and testcases, take 2.

Hans-Peter Nilsson hans-peter.nilsson@axis.com
Tue Jul 4 21:10:00 GMT 2000


This patch replaces the previous one.  The previous patch did not handle
multidigit numbers that had been "formatted" with a leading and trailing
underscore.  This patch also fixes handling of negative numbers with such
a leading and trailing underscore; those numbers were previously
incorrectly handled.

An alternative change would be to make consume_count_with_underscores
handle those numbers, with a necessary change to its interface so negative
numbers can be returned.  That would naturally include changing all its
callers, a larger change.  At this point I'd rather make locally limited
changes to cplus-dem.c; the mangler-demangler interface seems brittle.

I can provide the C++ code that emitted the symbols in the testcases, if
challenged.

Ok to commit?

2000-07-05  Hans-Peter Nilsson  <hp@axis.com>

	* cplus-dem.c (demangle_integral_value): Strip an optional
	following underscore cautiously.  Handle negative numbers.
	* testsuite/demangle-expected: Add 9 tests.

Index: demangle-expected
===================================================================
RCS file: /cvs/gcc/egcs/libiberty/testsuite/demangle-expected,v
retrieving revision 1.4
diff -p -c -r1.4 demangle-expected
*** demangle-expected	1999/10/19 17:52:52	1.4
--- demangle-expected	2000/07/05 03:59:13
*************** f(Bar<21>, int)
*** 2486,2488 ****
--- 2486,2524 ----
  --format=gnu
  f__FGt3Bar1i24XY_t
  f(Bar<2>, XY_t)
+ #
+ --format=gnu
+ foo__H1Zt2TA2ZRCiZt2NA1Ui9_X01_i
+ int foo<TA<int const &, NA<9> > >(TA<int const &, NA<9> >)
+ #
+ --format=gnu
+ foo__H1Zt2TA2ZcZt2NA1Ui_20__X01_i
+ int foo<TA<char, NA<20> > >(TA<char, NA<20> >)
+ #
+ --format=gnu
+ foo__H1Zt2TA2ZiZt8N___A___1Ui_99__X01_i
+ int foo<TA<int, N___A___<99> > >(TA<int, N___A___<99> >)
+ #
+ --format=gnu
+ foo__H1Zt2TA2ZRCiZt2NA1im1_X01_i
+ int foo<TA<int const &, NA<-1> > >(TA<int const &, NA<-1> >)
+ #
+ --format=gnu
+ foo__H1Zt2TA2ZRCiZt2NA1im9_X01_i
+ int foo<TA<int const &, NA<-9> > >(TA<int const &, NA<-9> >)
+ #
+ --format=gnu
+ foo__H1Zt2TA2ZcZt2NA1i_m20__X01_i
+ int foo<TA<char, NA<-20> > >(TA<char, NA<-20> >)
+ #
+ --format=gnu
+ foo__H1Zt2TA2ZcZt2NA1im1_X01_i
+ int foo<TA<char, NA<-1> > >(TA<char, NA<-1> >)
+ #
+ --format=gnu
+ foo__H1Zt2TA2ZiZt4N__A1im9_X01_i
+ int foo<TA<int, N__A<-9> > >(TA<int, N__A<-9> >)
+ #
+ --format=gnu
+ foo__H1Zt2TA2ZiZt4N__A1i_m99__X01_i
+ int foo<TA<int, N__A<-99> > >(TA<int, N__A<-99> >)
Index: cplus-dem.c
===================================================================
RCS file: /cvs/gcc/egcs/libiberty/cplus-dem.c,v
retrieving revision 1.56
diff -p -c -r1.56 cplus-dem.c
*** cplus-dem.c	2000/06/05 02:28:41	1.56
--- cplus-dem.c	2000/07/05 03:48:53
*************** demangle_integral_value (work, mangled, 
*** 1521,1526 ****
--- 1521,1531 ----
      {
        int value;
  
+       /* By default, we let the number decide whether we shall consume an
+ 	 underscore.  */
+       int consume_following_underscore = 0;
+       int leave_following_underscore = 0;
+ 
        success = 0;
  
        /* Negative numbers are indicated with a leading `m'.  */
*************** demangle_integral_value (work, mangled, 
*** 1529,1545 ****
  	  string_appendn (s, "-", 1);
  	  (*mangled)++;
  	}
  
-       /* Read the rest of the number.  */
-       value = consume_count_with_underscores (mangled);
        if (value != -1)
  	{
  	  char buf[INTBUF_SIZE];
  	  sprintf (buf, "%d", value);
  	  string_append (s, buf);
  
! 	  /* If the next character is an underscore, skip it.  */
! 	  if (**mangled == '_')
  	    (*mangled)++;
  
  	  /* All is well.  */
--- 1534,1582 ----
  	  string_appendn (s, "-", 1);
  	  (*mangled)++;
  	}
+       else if (mangled[0][0] == '_' && mangled[0][1] == 'm')
+ 	{
+ 	  /* Since consume_count_with_underscores does not handle the
+ 	     `m'-prefix we must do it here, using consume_count and
+ 	     adjusting underscores: we have to consume the underscore
+ 	     matching the prepended one.  */
+ 	  consume_following_underscore = 1;
+ 	  string_appendn (s, "-", 1);
+ 	  (*mangled) += 2;
+ 	}
+       else if (**mangled == '_')
+ 	{
+ 	  /* Do not consume a following underscore;
+ 	     consume_following_underscore will consume what should be
+ 	     consumed.  */
+ 	  leave_following_underscore = 1;
+ 	}
+ 
+       /* We must call consume_count if we expect to remove a trailing
+ 	 underscore, since consume_count_with_underscores expects
+ 	 the leading underscore (that we consumed) if it is to handle
+ 	 multi-digit numbers.  */
+       if (consume_following_underscore)
+ 	value = consume_count (mangled);
+       else
+ 	value = consume_count_with_underscores (mangled);
  
        if (value != -1)
  	{
  	  char buf[INTBUF_SIZE];
  	  sprintf (buf, "%d", value);
  	  string_append (s, buf);
+ 
+ 	  /* Numbers not otherwise delimited, might have an underscore
+ 	     appended as a delimeter, which we should skip.
  
! 	     ??? This used to always remove a following underscore, which
! 	     is wrong.  If other (arbitrary) cases are followed by an
! 	     underscore, we need to do something more radical.  */
! 
! 	  if ((value > 9 || consume_following_underscore)
! 	      && ! leave_following_underscore
! 	      && **mangled == '_')
  	    (*mangled)++;
  
  	  /* All is well.  */
*************** demangle_template_value_parm (work, mang
*** 1704,1710 ****
     template parameters (e.g. S) is placed in TRAWNAME if TRAWNAME is
     non-NULL.  If IS_TYPE is nonzero, this template is a type template,
     not a function template.  If both IS_TYPE and REMEMBER are nonzero,
!    the tmeplate is remembered in the list of back-referenceable
     types.  */
  
  static int
--- 1741,1747 ----
     template parameters (e.g. S) is placed in TRAWNAME if TRAWNAME is
     non-NULL.  If IS_TYPE is nonzero, this template is a type template,
     not a function template.  If both IS_TYPE and REMEMBER are nonzero,
!    the template is remembered in the list of back-referenceable
     types.  */
  
  static int

brgds, H-P


More information about the Gcc-patches mailing list