Bug 5955 – core.demangle fail to parse NaN and Infinity.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-05-08T02:51:00Z
Last change time
2011-06-19T11:38:56Z
Keywords
patch
Assigned to
nobody
Creator
kennytm

Comments

Comment #0 by kennytm — 2011-05-08T02:51:15Z
For example, the program ------------------------------------------- module y; template TTTTTTTTTT(float v) { void TTTTTTTTTT() { } } void main() { TTTTTTTTTT!1.0f(); TTTTTTTTTT!(float.nan)(); TTTTTTTTTT!(float.infinity)(); } ------------------------------------------- generates the symbols _D1y22__T10TTTTTTTTTTVfeINFZ10TTTTTTTTTTFZv _D1y22__T10TTTTTTTTTTVfeNANZ10TTTTTTTTTTFZv _D1y23__T10TTTTTTTTTTVfe8PN3Z10TTTTTTTTTTFZv which the demangler can only recognize 1 out of 3: void y.__T10TTTTTTTTTTVfeINFZ.TTTTTTTTTT() // fail void y.__T10TTTTTTTTTTVfeNANZ.TTTTTTTTTT() // fail void y.TTTTTTTTTT!(1).TTTTTTTTTT() // ok
Comment #1 by kennytm — 2011-05-08T03:15:42Z
Patch: @@ -354,6 +354,14 @@ private struct Demangle tbuf[tlen++] = '-'; next(); } + if( 'I' == tok() ) // INF + { + match( "INF" ); + bool isNegative = tlen == 1; + debug(info) printf( "got (%sINF)\n", isNegative ? "N" : "" ); + put( isNegative ? "-real.infinity" : "real.infinity" ); + return; + } tbuf[tlen++] = '0'; tbuf[tlen++] = 'X'; if( !isHexDigit( tok() ) ) @@ -362,6 +370,19 @@ private struct Demangle tbuf[tlen++] = '.'; next(); + if( 'N' == tok() ) // NAN + { + if( tbuf[0] == '-' && tbuf[3] == 'A' ) + { + next(); + debug(info) printf( "got (NAN)\n" ); + put( "real.nan" ); + return; + } + else + error( "Unexpected 'N'" ); + } + while( isHexDigit( tok() ) ) { tbuf[tlen++] = tok();
Comment #2 by kennytm — 2011-05-08T09:47:01Z
Comment #3 by kennytm — 2011-06-19T11:38:56Z