Bug 1134 – incorrect calling convention used

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-04-12T16:31:00Z
Last change time
2014-02-16T15:21:22Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
CppCoder

Attachments

IDFilenameSummaryContent-TypeSize
138test.dtest casetext/plain1468

Comments

Comment #0 by CppCoder — 2007-04-12T16:31:36Z
the following code compiles to the asm after it. Notice that only two parameters are pushed in the call to dllMain, when there should be three. int main( char [][]args ) { uint a; uint b; uint c; extern (Windows) BOOL function( HMODULE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) dllMain; a = 1; b = 2; c = 3; dllMain = cast(typeof(dllMain))(a + b); asm { int 3; } //as a reference point dllMain( cast(HMODULE)c, DLL_PROCESS_ATTACH, null ); return 0; } 00402010 /$ C8 100000 ENTER 10,0 00402014 |. 53 PUSH EBX 00402015 |. CC INT3 00402016 |. 31C0 XOR EAX,EAX 00402018 |. 8945 F0 MOV DWORD PTR SS:[EBP-10],EAX 0040201B |. 8945 F4 MOV DWORD PTR SS:[EBP-C],EAX 0040201E |. 8945 F8 MOV DWORD PTR SS:[EBP-8],EAX 00402021 |. 8945 FC MOV DWORD PTR SS:[EBP-4],EAX 00402024 |. B9 01000000 MOV ECX,1 00402029 |. 894D F0 MOV DWORD PTR SS:[EBP-10],ECX 0040202C |. BA 02000000 MOV EDX,2 00402031 |. 8955 F4 MOV DWORD PTR SS:[EBP-C],EDX 00402034 |. C745 F8 030000>MOV DWORD PTR SS:[EBP-8],3 0040203B |. 8D1C11 LEA EBX,DWORD PTR DS:[ECX+EDX] 0040203E |. 895D FC MOV DWORD PTR SS:[EBP-4],EBX 00402041 |. CC INT3 00402042 |. FF75 F8 PUSH DWORD PTR SS:[EBP-8] ;push #1 (c) 00402045 |. 51 PUSH ECX ;push #2 (DLL_PROCESS_ATTACH) 00402046 |. FF55 FC CALL DWORD PTR SS:[EBP-4] ;call dllMain 00402049 |. 31C0 XOR EAX,EAX 0040204B |. 5B POP EBX 0040204C |. C9 LEAVE 0040204D \. C3 RETN
Comment #1 by CppCoder — 2007-04-12T16:32:47Z
Created attachment 138 test case
Comment #2 by davidl — 2007-04-12T22:12:31Z
It's because extern(windows) doesn't take effect on the calling convention I think. EAX is 0 and optimized
Comment #3 by bugzilla — 2007-04-20T13:20:20Z
Fixed DMD 1.013
Comment #4 by thomas-dloop — 2007-04-23T12:54:57Z
*** Bug 957 has been marked as a duplicate of this bug. ***