c++/5390: Libiberty fails to demangle multi-digit template parameters.

Carlo Wood carlo@alinoe.com
Tue Mar 11 02:23:00 GMT 2003


On Mon, Mar 10, 2003 at 03:03:05PM -0600, Wolfgang Bangerth wrote:
> >  So, as far as I am concerned you can close this PR.
> 
> Does this still hold given DJ's mail?
> 
> > (Personally, I'd fix it though if I were you - but I am a perfectionist).
> 
> I might if I could. I have no knowledge of gcc, libiberty, etc at all. My 
> place is gnats, beyond that I can only try to get patch creators and 
> reviewers into contact -- usually a fruitless endeavor...

I tested it again and, as I've written to DJ in private, it seems
that my patch WAS applied more or less to gcc version 3.1.
However, the way it is now is that it doesn't work for negative
template integrals less than -9.

For example:

/usr/src/gcc/gcc-cvs-3.3/libiberty>echo 'main(int argc, char* argv[]) { printf("%s\n", cplus_demangle(argv[1], 3)); }' > main.c
/usr/src/gcc/gcc-cvs-3.3/libiberty>gcc -I../include cplus-dem.c safe-ctype.c xmalloc.c xexit.c xstrdup.c cp-demangle.c dyn-string.c main.c
/usr/src/gcc/gcc-cvs-3.3/libiberty>a.out X__FGt3Bar1im10i
X(Bar<-1>, , int)

I corrected cplus-dem.c again to completely reflect my original patch
after which I get correctly:

/usr/src/gcc/gcc-cvs-3.3/libiberty>a.out X__FGt3Bar1im10i
X(Bar<-10>, int)


The new diff is attached.

Log entry:


2003-03-10  Carlo Wood  <carlo@gnu.org>

        * cplus-dem.c (demangle_integral_value): Correction to reflect
	patch of 2002-01-10 in order to also make negative multi-digits
	without leading underscore work.

-- 
Carlo Wood <carlo@alinoe.com>
-------------- next part --------------
Index: cplus-dem.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/cplus-dem.c,v
retrieving revision 1.89.4.1
diff -u -d -p -r1.89.4.1 cplus-dem.c
--- cplus-dem.c	4 Mar 2003 02:57:48 -0000	1.89.4.1
+++ cplus-dem.c	11 Mar 2003 02:07:23 -0000
@@ -1797,31 +1797,34 @@ demangle_integral_value (work, mangled, 
 
       success = 0;
 
-      /* Negative numbers are indicated with a leading `m'.  */
-      if (**mangled == 'm')
-	{
-	  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.  */
-	  multidigit_without_leading_underscore = 1;
-	  string_appendn (s, "-", 1);
-	  (*mangled) += 2;
-	}
-      else if (**mangled == '_')
-	{
-	  /* Do not consume a following underscore;
-	     multidigit_without_leading_underscore will consume what should be
-	     consumed.  */
-	  leave_following_underscore = 1;
+      if (**mangled == '_')
+        {
+	  if (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.  */
+	      multidigit_without_leading_underscore = 1;
+	      string_appendn (s, "-", 1);
+	      (*mangled) += 2;
+	    }
+	  else
+	    {
+	      /* Do not consume a following underscore;
+	         consume_count_with_underscores will consume what
+	         should be consumed.  */
+	      leave_following_underscore = 1;
+	    }
 	}
       else
 	{
+	  /* Negative numbers are indicated with a leading `m'.  */
+	  if (**mangled == 'm')
+	  {
+	    string_appendn (s, "-", 1);
+	    (*mangled)++;
+	  }
 	  /* Since consume_count_with_underscores does not handle
 	     multi-digit numbers that do not start with an underscore,
 	     and this number can be an integer template parameter,
@@ -1862,7 +1865,7 @@ demangle_integral_value (work, mangled, 
 	  /* All is well.  */
 	  success = 1;
 	}
-    }
+      }
 
   return success;
 }


More information about the Gcc-patches mailing list