Bug 12873 - [3.3 only] __cxa_demangle not working as specified in 3.3.2 ABI
Summary: [3.3 only] __cxa_demangle not working as specified in 3.3.2 ABI
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: 3.3.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-02 00:05 UTC by merkert
Modified: 2003-12-05 07:04 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build: gcc (GCC) 3.3.2
Known to work:
Known to fail:
Last reconfirmed: 2003-11-02 02:21:55


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description merkert 2003-11-02 00:05:16 UTC
This test program produces different results for 3.3.2 and 3.4.

cat > test.c <<EOF
#include <stdio.h>
#include <stdlib.h>

extern char *__cxa_demangle (const char *__mangled_name,
                             char *__output_buffer,
                             __SIZE_TYPE__ *__length,
                             int *__status);


int main(int argc, char** argv)
{
  for (int i=1;i<argc;++i) {
    int status;
    char* res = __cxa_demangle(argv[i],0,0,&status);
    if (res!=NULL || status!=0) {
      printf("Demangled '%s' as '%s'\n",argv[i],res);
    }
    else {
      printf("Could not demangle '%s'\n",argv[i]);
    }
    free(res);
  }
  return 0;
}

EOF

/local/gcc/bin/gcc -o test test.c -std=c99 /local/gcc/lib/libstdc++.a

'./test hello'

produces

Demangled 'hello' as 'unsigned char'

Also, if I don't pass the status flag pointer, then  I get 

Could not demangle 'hello'


Code is working in mainline, but it would be nice to have it work in 3.3
release series as well. 

Can this be backported?
Comment 1 Carlo Wood 2003-11-02 02:21:53 UTC
The demangler in 3.4 is a complete rewrite, it cannot be
back ported.  What needs to be fixed here is that the
__cxa_demangle implementation in 3.3

1) Doesn't take the string length of the input into account
   (ie, it demangles what it can and ignores any trailing
    characters).  It should fail if any characters are trailing.
2) A single character should NOT be considered to be a mangled
   type name (a builtin-type) - but returned as-is.

Instead, it demangles the 'h' and ignores the rest.

I am afraid I have no time to write patches for the 3.3 branch,
but I am sure this would be a small patch.
Comment 2 Benjamin Kosnik 2003-12-05 07:04:33 UTC
The 3.3.x __cxa_demangle code is considered broken. It's been re-written a
couple of times now.