This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: other/5390: Libiberty fails to demangle multi-digit template parameters.
- From: Carlo Wood <carlo at alinoe dot com>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 15 Jan 2002 18:36:01 -0000
- Subject: Re: other/5390: Libiberty fails to demangle multi-digit template parameters.
- Reply-to: Carlo Wood <carlo at alinoe dot com>
The following reply was made to PR other/5390; it has been noted by GNATS.
From: Carlo Wood <carlo@alinoe.com>
To: gcc-patches@gcc.gnu.org
Cc: dj@redhat.com, gcc-gnats@gcc.gnu.org
Subject: Re: other/5390: Libiberty fails to demangle multi-digit template parameters.
Date: Tue, 15 Jan 2002 19:35:23 +0100
--mYCpIKhGyMATD0i+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
As promised, sending this patch also to gcc-patches@gcc.gnu.org
The following patch fixes the problem that an integral template
parameter larger than 9 or smaller than -9 was not demangled
correctly (and even led to a core dump in libiberty).
(This is only related to the old ABI, g++-2.95.x thus).
Basically the change is as follows:
Instead of reading integer numbers as
[m]<digit>
or
_[m]<digit>[<digit>...]_
It now simply reads
[m]<digit>[<digit>...]
or
_[m]<digit>[<digit>...]_
This is not a problem since g++-2.95.x never mangles
names in a way that there would follow a digit that
does not belong to the number. However, the testsuite
assumed that this was the case and was testing several
incorrect mangled names. I wrote little test cases
to generate the symbols used in order to make sure that
g++-2.95.3 indeed does generate mangled names as I
thought it was. This patch also incorporates these
changes (testsuite/demangle-expected).
Obviously, after applying this test we get:
~/c/src/libiberty>make check
make[1]: Entering directory `/home/carlo/c/src/libiberty/testsuite'
/bin/sh ./regress-demangle ./demangle-expected
All 646 tests passed
make[1]: Leaving directory `/home/carlo/c/src/libiberty/testsuite'
--
Carlo Wood <carlo@alinoe.com>
--mYCpIKhGyMATD0i+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="dem2.patch"
2002-01-10 Carlo Wood <carlo@gnu.org>
* cplus-dem.c (demangle_integral_value): Accept multi-digit
numbers that do not start with an underscore; This is needed
for integer template parameters. This doesn't break anything
because multi-digit numbers are never followed by a digit.
* testsuite/demangle-expected: Corrected all mangled test
cases with multi-digit template parameters: g++ 2.95.x does
not generate underscores around these parameters.
Index: cplus-dem.c
===================================================================
RCS file: /cvs/src/src/libiberty/cplus-dem.c,v
retrieving revision 1.27
diff -u -d -p -r1.27 cplus-dem.c
--- cplus-dem.c 2002/01/03 00:25:57 1.27
+++ cplus-dem.c 2002/01/15 17:45:04
@@ -1787,40 +1787,54 @@ demangle_integral_value (work, mangled,
/* By default, we let the number decide whether we shall consume an
underscore. */
- int consume_following_underscore = 0;
+ int multidigit_without_leading_underscore = 0;
int leave_following_underscore = 0;
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')
+ if (**mangled == '_')
{
- /* 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;
+ 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 if (**mangled == '_')
+ else
{
- /* Do not consume a following underscore;
- consume_following_underscore will consume what should be
- consumed. */
+ /* 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,
+ we have to call consume_count. */
+ multidigit_without_leading_underscore = 1;
+ /* These multi-digit numbers never end on an underscore,
+ so if there is one then don't eat it. */
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
+ /* We must call consume_count if we have no leading underscore,
+ since consume_count_with_underscores expects one (that we
+ consumed or wasn't there to begin with) if it is to handle
multi-digit numbers. */
- if (consume_following_underscore)
+ if (multidigit_without_leading_underscore)
value = consume_count (mangled);
else
value = consume_count_with_underscores (mangled);
@@ -1838,7 +1852,7 @@ demangle_integral_value (work, mangled,
is wrong. If other (arbitrary) cases are followed by an
underscore, we need to do something more radical. */
- if ((value > 9 || consume_following_underscore)
+ if ((value > 9 || multidigit_without_leading_underscore)
&& ! leave_following_underscore
&& **mangled == '_')
(*mangled)++;
Index: testsuite/demangle-expected
===================================================================
RCS file: /cvs/src/src/libiberty/testsuite/demangle-expected,v
retrieving revision 1.6
diff -u -d -p -r1.6 demangle-expected
--- demangle-expected 2001/12/13 00:05:32 1.6
+++ demangle-expected 2002/01/15 17:45:06
@@ -2476,15 +2476,15 @@ fn__FPQ21n1cPMQ21n1cFPQ21n1c_i
fn(n::c *, int (n::c::*)(n::c *))
#
--format=gnu
-f__FGt3Bar1i21i
+f__FGt3Bar1i2G1i
f(Bar<2>, i)
#
--format=gnu
-f__FGt3Bar1i_21_i
+f__FGt3Bar1i21i
f(Bar<21>, int)
#
--format=gnu
-f__FGt3Bar1i24XY_t
+f__FGt3Bar1i2G4XY_t
f(Bar<2>, XY_t)
#
--format=gnu
@@ -2492,11 +2492,11 @@ foo__H1Zt2TA2ZRCiZt2NA1Ui9_X01_i
int foo<TA<int const &, NA<9> > >(TA<int const &, NA<9> >)
#
--format=gnu
-foo__H1Zt2TA2ZcZt2NA1Ui_20__X01_i
+foo__H1Zt2TA2ZcZt2NA1Ui20_X01_i
int foo<TA<char, NA<20> > >(TA<char, NA<20> >)
#
--format=gnu
-foo__H1Zt2TA2ZiZt8N___A___1Ui_99__X01_i
+foo__H1Zt2TA2ZiZt8N___A___1Ui99_X01_i
int foo<TA<int, N___A___<99> > >(TA<int, N___A___<99> >)
#
--format=gnu
@@ -2508,7 +2508,7 @@ foo__H1Zt2TA2ZRCiZt2NA1im9_X01_i
int foo<TA<int const &, NA<-9> > >(TA<int const &, NA<-9> >)
#
--format=gnu
-foo__H1Zt2TA2ZcZt2NA1i_m20__X01_i
+foo__H1Zt2TA2ZcZt2NA1im20_X01_i
int foo<TA<char, NA<-20> > >(TA<char, NA<-20> >)
#
--format=gnu
@@ -2520,7 +2520,7 @@ 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
+foo__H1Zt2TA2ZiZt4N__A1im99_X01_i
int foo<TA<int, N__A<-99> > >(TA<int, N__A<-99> >)
#
--format=gnu
@@ -2528,15 +2528,15 @@ __opi__t2TA2ZiZt4N__A1i9
TA<int, N__A<9> >::operator int(void)
#
--format=gnu
-__opi__t2TA2ZiZt8N___A___1i_m99_
+__opi__t2TA2ZiZt8N___A___1im99
TA<int, N___A___<-99> >::operator int(void)
#
--format=gnu
-foo___bar__baz_____H1Zt2TA2ZiZt8N___A___1i_99__X01_i
+foo___bar__baz_____H1Zt2TA2ZiZt8N___A___1i99_X01_i
int foo___bar__baz___<TA<int, N___A___<99> > >(TA<int, N___A___<99> >)
#
--format=gnu
-foo__bar___foobar_____t2TA2ZiZt8N___A___1i_m99_
+foo__bar___foobar_____t2TA2ZiZt8N___A___1im99
TA<int, N___A___<-99> >::foo__bar___foobar___(void)
#
--format=gnu
--mYCpIKhGyMATD0i+--