Thread overview
[Issue 10058] New: Inconsistent mangling between C++ and extern(C++).
May 10, 2013
Iain Buclaw
May 10, 2013
Iain Buclaw
May 10, 2013
Iain Buclaw
May 10, 2013
Iain Buclaw
May 10, 2013
Iain Buclaw
May 10, 2013
Iain Buclaw
May 15, 2013
yebblies
May 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10058

           Summary: Inconsistent mangling between C++ and extern(C++).
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: ibuclaw@ubuntu.com


--- Comment #0 from Iain Buclaw <ibuclaw@ubuntu.com> 2013-05-10 08:24:13 PDT ---
Noticed this when looking at bug 7024.

test.cc:
void foo1(void*) {}
void foo2(void (*)(void*)) {}
void foo3(void* (*)(void*)) {}
void foo4(void (*)(void*), void*) {}
void foo5(void* (*)(void*), void*) {}
void foo6(void (*)(void*), void*, void*) {}
void foo6(void* (*)(void*), void*, void*) {}


test.d:
extern(C++) void foo1(void*) {}
extern(C++) void foo2(void function(void*)) {}
extern(C++) void foo3(void* function(void*)) {}
extern(C++) void foo4(void function(void*), void*) {}
extern(C++) void foo5(void* function(void*), void*) {}
extern(C++) void foo6(void function(void*), void*, void*) {}
extern(C++) void foo6(void* function(void*), void*, void*) {}


g++ produces following mangling:
---
_Z4foo1Pv
_Z4foo2PFvPvE
_Z4foo3PFPvS_E
_Z4foo4PFvPvES_
_Z4foo5PFPvS_ES_
_Z4foo6PFvPvES_S_
_Z4foo6PFPvS_ES_S_
---

dmd produces following mangling:
---
_Z4foo1Pv
_Z4foo2PFvPvE
_Z4foo3PFPvS0_E
_Z4foo4PFvPvES0_
_Z4foo5PFPvS0_ES0_
_Z4foo6PFvPvES0_S0_
_Z4foo6PFPvS0_ES0_S0_
---


The code in cppmangle.c is:
---
/* Sequence is S_, S0_, .., S9_, SA_, ..., SZ_, S10_, ...
 */
buf->writeByte('S');
if (i)
    writeBase36(buf, i - 1);
---


So something is wrong with the logic before this point...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10058


Iain Buclaw <ibuclaw@ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@ubuntu.com


--- Comment #1 from Iain Buclaw <ibuclaw@ubuntu.com> 2013-05-10 09:02:08 PDT ---
A better example:

test.cc:
void foo1(void* (*)(void*)) {}
void foo2(void* (*)(void*), void*) {}
void foo3(void* (*)(void*), void* (*)(void*)) {}
void foo4(void* (*)(void*), void*, void*) {}
void foo5(void* (*)(void*), void* (*)(void*), void*) {}
void foo6(void* (*)(void*), void* (*)(void*), void* (*)(void*)) {}

test.d:
extern(C++) void foo1(void* function(void*)) {}
extern(C++) void foo2(void* function(void*), void*) {}
extern(C++) void foo3(void* function(void*), void* function(void*)) {}
extern(C++) void foo4(void* function(void*), void*, void*) {}
extern(C++) void foo5(void* function(void*), void* function(void*), void*) {}
extern(C++) void foo6(void* function(void*), void* function(void*), void*
function(void*)) {}


testcc.o
---
_Z4foo1PFPvS_E
_Z4foo2PFPvS_ES_
_Z4foo3PFPvS_ES1_
_Z4foo4PFPvS_ES_S_
_Z4foo5PFPvS_ES1_S_
_Z4foo6PFPvS_ES1_S1_


testd.o
---
_Z4foo1PFPvS0_E
_Z4foo2PFPvS0_ES0_
_Z4foo3PFPvS0_ES1_
_Z4foo4PFPvS0_ES0_S0_
_Z4foo5PFPvS0_ES1_S0_
_Z4foo6PFPvS0_ES1_S1_

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10058



--- Comment #2 from Iain Buclaw <ibuclaw@ubuntu.com> 2013-05-10 09:03:52 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2007

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10058



--- Comment #3 from Iain Buclaw <ibuclaw@ubuntu.com> 2013-05-10 09:07:40 PDT ---
Hmm... tested with patch (using gdc) there is still a discrepancy.

testcc.o
---
_Z4foo1PFPvS_E
_Z4foo2PFPvS_ES_
_Z4foo3PFPvS_ES1_
_Z4foo4PFPvS_ES_S_
_Z4foo5PFPvS_ES1_S_
_Z4foo6PFPvS_ES1_S1_


testd.o
---
_Z4foo1PFPvS_E
_Z4foo2PFPvS_ES_
_Z4foo3PFPvS_ES0_
_Z4foo4PFPvS_ES_S_
_Z4foo5PFPvS_ES0_S_
_Z4foo6PFPvS_ES0_S0_



Looks like the sequence goes:

S_, S1_, .., S9_, SA_, ..., SZ_, S10_, ...


Will need to check this to make sure...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10058



--- Comment #4 from Iain Buclaw <ibuclaw@ubuntu.com> 2013-05-10 09:38:24 PDT ---
That is, if I can find a way to trigger it. =)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10058



--- Comment #5 from Iain Buclaw <ibuclaw@ubuntu.com> 2013-05-10 09:50:05 PDT ---
With current pull:

test.cc:
void foo1(void* (*)(void*)) {}
void foo2(void* (*)(void*), void* (*)(void*)) {}
void foo3(void* (*)(void*), void* (*)(const void*)) {}
void foo4(void* (*)(void*), void* (*)(const void*), const void* (*)(void*)) {}


test.d:
extern(C++) void foo1(void* function(void*)) {}
extern(C++) void foo2(void* function(void*), void* function(void*)) {}
extern(C++) void foo3(void* function(void*), void* function(const (void)*)) {}
extern(C++) void foo4(void* function(void*), void* function(const (void)*),
const(void)* function(void*)) {}


testcc.o
---
_Z4foo1PFPvS_E
_Z4foo2PFPvS_ES1_
_Z4foo3PFPvS_EPFS_PKvE
_Z4foo4PFPvS_EPFS_PKvEPFS3_S_E


testd.o
---
_Z4foo1PFPvS_E
_Z4foo2PFPvS_ES1_
_Z4foo3PFPvS_EPFS_PKvE
_Z4foo4PFPvS_EPFS_PKvEPFS3_S_E



Looks good so far.  Can anyone think of any other ways to break it?

Regards
Iain

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10058



--- Comment #6 from github-bugzilla@puremagic.com 2013-05-14 23:04:31 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/2e5d2ded0522abca587091b2ce7e84102decee58 Fix Issue 10058.

https://github.com/D-Programming-Language/dmd/commit/60dee0bde7db72c84a99b18a911ad14e5bf88db9 Merge pull request #2007 from ibuclaw/cppmangle

Fix Issue 10058 - Inconsistent mangling between C++ and extern(C++).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 15, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10058


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies@gmail.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------