Bug 24130 – ImportC: Windows headers use inline asm with different syntax

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2023-09-01T18:51:35Z
Last change time
2023-09-11T15:01:11Z
Keywords
iasm, ImportC, pull
Assigned to
No Owner
Creator
Jeffrey H. Johnson

Comments

Comment #0 by trnsz — 2023-09-01T18:51:35Z
DMD v2.105.0, Windows 11, latest MSVC community edition: >TYPE test.c #include <windows.h> int main(void) { return 0; } >DMD -m32 -v test.c predefs DigitalMars LittleEndian D_Version2 all Windows Win32 CRuntime_Microsoft CppRuntime_Microsoft D_InlineAsm D_InlineAsm_X86 X86 assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat binary dmd version v2.105.0-dirty config C:\D\dmd2\windows\bin64\sc.ini DFLAGS -IC:\D\dmd2\windows\bin64\..\..\src\phobos -IC:\D\dmd2\windows\bin64\..\..\src\druntime\import include C:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX64\x86\cl.exe /P /Zc:preprocessor /PD /nologo test.c /FIC:\D\dmd2\windows\bin64\..\..\src\druntime\import\importc.h /Fitest.i parse test C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(1016): Error: `asm` statements must end in `;` C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(1032): Error: `asm` statements must end in `;` C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(1048): Error: `asm` statements must end in `;` C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(13826): Error: found `i64` when expecting `)` C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(13826): Error: found `i64` when expecting `)` C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(13826): Error: found `i64` when expecting `)` C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(13826): Error: found `i64` when expecting `)` C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(13826): Error: found `i64` when expecting `)` C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(13826): Error: found `)` when expecting `]` C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um\winnt.h(13826): Error: `=`, `;` or `,` expected to end declaration instead of `)`
Comment #1 by bugzilla — 2023-09-05T04:46:31Z
Can you please take a look at the generated test.i file and post which lines in it are failing?
Comment #2 by trnsz — 2023-09-05T21:25:41Z
(In reply to Walter Bright from comment #1) > Can you please take a look at the generated test.i file and post which lines > in it are failing? Yes, I'll try to get this done today.
Comment #3 by dfj1esp02 — 2023-09-06T07:26:50Z
I have this code around that line: __inline ULONGLONG NTAPI Int64ShrlMod32 ( _In_ ULONGLONG Value, _In_ DWORD ShiftCount ) { __asm { mov ecx, ShiftCount mov eax, dword ptr [Value] mov edx, dword ptr [Value+4] shrd eax, edx, cl shr edx, cl } } So D complains about absence of semicolon after the asm statement.
Comment #4 by trnsz — 2023-09-06T23:06:11Z
> So D complains about absence of semicolon after the asm statement. Can confirm.
Comment #5 by bugzilla — 2023-09-09T04:27:17Z
Looking at the file winnt.h, the inline assembler: -------------- #if defined(MIDL_PASS) || defined(RC_INVOKED) || defined(_M_CEE_PURE) \ || defined(_68K_) || defined(_MPPC_) \ || defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM) || defined(_M_ARM64) \ || defined(_M_HYBRID_X86_ARM64) // // Midl does not understand inline assembler. Therefore, the Rtl functions // are used for shifts by 0..31 and multiplies of 32-bits times 32-bits to // form a 64-bit product. // // // IA64 and AMD64 have native 64-bit operations that are just as fast as their // 32-bit counter parts. Therefore, the int64 data type is used directly to form // shifts of 0..31 and multiplies of 32-bits times 32-bits to form a 64-bit // product. // #define Int32x32To64(a, b) (((__int64)((long)(a))) * ((__int64)((long)(b)))) #define UInt32x32To64(a, b) (((unsigned __int64)((unsigned int)(a))) * ((unsigned __int64)((unsigned int)(b)))) #define Int64ShllMod32(a, b) (((unsigned __int64)(a)) << (b)) #define Int64ShraMod32(a, b) (((__int64)(a)) >> (b)) #define Int64ShrlMod32(a, b) (((unsigned __int64)(a)) >> (b)) #elif defined(_M_IX86) ... inline assembler versions go here ... #endif --------------------------------- And, well, the inline assembler format is different than ImportC's. So, try #define'ing _M_CEE_PURE to be 1 and see if that helps. As for the line 13826 errors, I cannot find "i64" in the version of winnt.h that I have. Perhaps you could quote the offending lines, please?
Comment #6 by dlang-bot — 2023-09-09T04:35:42Z
@WalterBright created dlang/dmd pull request #15595 "fix Issue 24130 - ImportC: Windows headers use inline asm with differ…" fixing this issue: - fix Issue 24130 - ImportC: Windows headers use inline asm with different syntax https://github.com/dlang/dmd/pull/15595
Comment #7 by dlang-bot — 2023-09-11T01:24:38Z
dlang/dmd pull request #15595 "fix Issue 24130 - ImportC: Windows headers use inline asm with differ…" was merged into master: - 05403c7aaf342af2bbb92f5a8cec121dda5dce98 by Walter Bright: fix Issue 24130 - ImportC: Windows headers use inline asm with different syntax https://github.com/dlang/dmd/pull/15595
Comment #8 by dfj1esp02 — 2023-09-11T15:01:11Z
i64 is used in some kind of cpu feature constants (Extended processor state configuration): #define XSTATE_MASK_LEGACY_FLOATING_POINT (1ui64 << (XSTATE_LEGACY_FLOATING_POINT)) #define XSTATE_MASK_LEGACY_SSE (1ui64 << (XSTATE_LEGACY_SSE))