aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@wasabisystems.com>2004-02-24 02:49:24 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2004-02-24 02:49:24 +0000
commit4a368ffd957ae319f3e608cd7c2e77d72857d78a (patch)
treebc72851c9f3e87d5398c7bdd12449baa2f2afa7b
parent8ad1c80ea8014f15b5d5101de011bc40bec661e7 (diff)
downloadgcc-4a368ffd957ae319f3e608cd7c2e77d72857d78a.zip
gcc-4a368ffd957ae319f3e608cd7c2e77d72857d78a.tar.gz
gcc-4a368ffd957ae319f3e608cd7c2e77d72857d78a.tar.bz2
cp-demangle.c (__cxa_demangle): It is not an error if status is not NULL.
2004-02-23 Ian Lance Taylor <ian@wasabisystems.com> * cp-demangle.c (__cxa_demangle): It is not an error if status is not NULL. It is an error if the mangled name is the same as a built-in type name. (main): If IN_GLIBCPP_V3 is defined, test __cxa_demangle rather than cplus_demangle_v3. From-SVN: r78348
-rw-r--r--libiberty/ChangeLog6
-rw-r--r--libiberty/cp-demangle.c57
2 files changed, 52 insertions, 11 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 586fa1f..97ba223 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,5 +1,11 @@
2004-02-23 Ian Lance Taylor <ian@wasabisystems.com>
+ * cp-demangle.c (__cxa_demangle): It is not an error if status is
+ not NULL. It is an error if the mangled name is the same as a
+ built-in type name.
+ (main): If IN_GLIBCPP_V3 is defined, test __cxa_demangle rather
+ than cplus_demangle_v3.
+
* dyn-string.c: Remove test of IN_LIBGCC2 and IN_GLIBCPP_V3 and
the associated #define of RETURN_ON_ALLOCATION_FAILURE.
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 19f191e..4d0dd7e 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3944,18 +3944,32 @@ __cxa_demangle (mangled_name, output_buffer, length, status)
char *demangled;
size_t alc;
- if (status == NULL)
- return NULL;
-
if (mangled_name == NULL)
{
- *status = -3;
+ if (status != NULL)
+ *status = -3;
return NULL;
}
if (output_buffer != NULL && length == NULL)
{
- *status = -3;
+ if (status != NULL)
+ *status = -3;
+ return NULL;
+ }
+
+ /* The specification for __cxa_demangle() is that if the mangled
+ name could be either an extern "C" identifier, or an internal
+ built-in type name, then we resolve it as the identifier. All
+ internal built-in type names are a single lower case character.
+ Frankly, this simplistic disambiguation doesn't make sense to me,
+ but it is documented, so we implement it here. */
+ if (mangled_name[1] == '\0'
+ && IS_LOWER (mangled_name[0])
+ && cplus_demangle_builtin_types[mangled_name[0] - 'a'].name != NULL)
+ {
+ if (status != NULL)
+ *status = -2;
return NULL;
}
@@ -3963,10 +3977,13 @@ __cxa_demangle (mangled_name, output_buffer, length, status)
if (demangled == NULL)
{
- if (alc == 1)
- *status = -1;
- else
- *status = -2;
+ if (status != NULL)
+ {
+ if (alc == 1)
+ *status = -1;
+ else
+ *status = -2;
+ }
return NULL;
}
@@ -3990,7 +4007,8 @@ __cxa_demangle (mangled_name, output_buffer, length, status)
}
}
- *status = 0;
+ if (status != NULL)
+ *status = 0;
return demangled;
}
@@ -4296,7 +4314,11 @@ main (argc, argv)
if (dyn_string_length (mangled) > 0)
{
+#ifdef IN_GLIBCPP_V3
+ s = __cxa_demangle (dyn_string_buf (mangled), NULL, NULL, NULL);
+#else
s = cplus_demangle_v3 (dyn_string_buf (mangled), options);
+#endif
if (s != NULL)
{
@@ -4328,9 +4350,16 @@ main (argc, argv)
for (i = optind; i < argc; ++i)
{
char *s;
+#ifdef IN_GLIBCPP_V3
+ int status;
+#endif
/* Attempt to demangle. */
+#ifdef IN_GLIBCPP_V3
+ s = __cxa_demangle (argv[i], NULL, NULL, &status);
+#else
s = cplus_demangle_v3 (argv[i], options);
+#endif
/* If it worked, print the demangled name. */
if (s != NULL)
@@ -4339,7 +4368,13 @@ main (argc, argv)
free (s);
}
else
- fprintf (stderr, "Failed: %s\n", argv[i]);
+ {
+#ifdef IN_GLIBCPP_V3
+ fprintf (stderr, "Failed: %s (status %d)\n", argv[i], status);
+#else
+ fprintf (stderr, "Failed: %s\n", argv[i]);
+#endif
+ }
}
}