Bug 4852 – core.demangle cannot demangle functions with class/struct return types

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-09-11T05:05:00Z
Last change time
2016-03-12T01:53:18Z
Keywords
patch
Assigned to
sean
Creator
r.sagitario

Attachments

IDFilenameSummaryContent-TypeSize
774demangle.patchcorrected patch including some additionstext/plain4573

Comments

Comment #0 by r.sagitario — 2010-09-11T05:05:20Z
There are similar bug reports regarding std.demangle, but as it is reimplemented in core.demangle, I've created this new bug report. for example: _D3dmd6Parser6Parser15parsePrimaryExpMFZC3dmd10Expression10Expression if demangled to dmd dmd.Parser.Parser.parsePrimaryExp() but it should be dmd.Expression.Expression dmd.Parser.Parser.parsePrimaryExp() This is caused by parseLName() not continue reading after eating the first identifier of the fully qualified class name. Index: demangle.d =================================================================== --- demangle.d (revision 390) +++ demangle.d (working copy) @@ -378,20 +378,26 @@ debug(trace) printf( "parseLName+\n" ); debug(trace) scope(success) printf( "parseLName-\n" ); - auto n = decodeNumber(); + while( true ) + { + auto n = decodeNumber(); - if( !n || n > buf.length || n > buf.length - pos ) - error( "LName must be at least 1 character" ); - if( '_' != tok() && !isAlpha( tok() ) ) - error( "Invalid character in LName" ); - foreach( e; buf[pos + 1 .. pos + n] ) - { - if( '_' != e && !isAlpha( e ) && !isDigit( e ) ) + if( !n || n > buf.length || n > buf.length - pos ) + error( "LName must be at least 1 character" ); + if( '_' != tok() && !isAlpha( tok() ) ) error( "Invalid character in LName" ); + foreach( e; buf[pos + 1 .. pos + n] ) + { + if( '_' != e && !isAlpha( e ) && !isDigit( e ) ) + error( "Invalid character in LName" ); + } + + put( buf[pos .. pos + n] ); + pos += n; + if( !isDigit( tok() ) ) + break; + put( "." ); } - - put( buf[pos .. pos + n] ); - pos += n; } /*
Comment #1 by r.sagitario — 2010-09-25T00:03:59Z
Created attachment 774 corrected patch including some additions Please ignore the previous patch, it is flawed and breaks demangling other symbols. What is actually necessary is to call parseQualifiedName instead of parseLName to get the full qualified name, but this involves a call to a function declared later which does not work with local functions, so I placed the local functions into a struct. Included is also a bug fix decoding string literals in template arguments (line 1064). This allows to reenable the 2 failing unittest symbols. I'm proposing to add an argument to demangle() whether the full type is requested or just the qualified name. I've added a function "decodeDmdString" to decompress symbols that are emitted compressed by dmd on windows. I think it is very much related to demangling, so it should have its place in this module, but a better name would be much appreciated.
Comment #2 by sean — 2010-11-02T15:46:10Z
I've applied the patch and made a few tweaks. Still not sure exactly how I want to expose the AddType feature though. For now I just wanted to get the patch in.
Comment #3 by r.sagitario — 2011-02-14T23:28:17Z
In my version of druntime I've exposed a version with AddType support by adding a function like this: char[] demangle( const(char)[] buf, bool addType_, char[] dst = null ) { auto d = Demangle(buf, addType_ ? Demangle.AddType.yes : Demangle.AddType.no, dst); return d(); }
Comment #4 by andrew — 2016-03-12T01:53:18Z
This appears to have been fixed.