Issue 23894 - ImportC: _InterlockedExchangeAdd and a ton of other VC intrinsics are not recognized
Summary: ImportC: _InterlockedExchangeAdd and a ton of other VC intrinsics are not rec...
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P1 normal
Assignee: No Owner
URL:
Keywords: ImportC
Depends on:
Blocks:
 
Reported: 2023-05-05 19:58 UTC by Max Samukha
Modified: 2024-03-11 05:49 UTC (History)
2 users (show)

See Also:


Attachments
VC intrinsics referenced by windows.h (3.55 KB, text/x-csrc)
2023-06-03 06:53 UTC, Max Samukha
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2023-05-05 19:58:20 UTC
"Windows.h" intrinsics:

main.obj : error LNK2019: unresolved external symbol _InterlockedExchangeAdd referenced in function _InlineInterlockedAdd
main.obj : error LNK2019: unresolved external symbol _InterlockedExchangeAdd64 referenced in function _InlineInterlockedAdd64
main.obj : error LNK2019: unresolved external symbol _mul128 referenced in function MultiplyExtract128
main.obj : error LNK2019: unresolved external symbol __shiftright128 referenced in function MultiplyExtract128
main.obj : error LNK2019: unresolved external symbol _umul128 referenced in function UnsignedMultiplyExtract128
main.obj : error LNK2019: unresolved external symbol _ReadWriteBarrier referenced in function BarrierAfterRead
main.obj : error LNK2019: unresolved external symbol __stosb referenced in function RtlSecureZeroMemory
main.obj : error LNK2019: unresolved external symbol __readgsqword referenced in function NtCurrentTeb

Fun!
Comment 1 Walter Bright 2023-05-11 06:01:59 UTC
ImportC doesn't support gcc's inline assembler, either. Is the use of these intrinsics blockable with some macro?
Comment 2 Max Samukha 2023-05-11 17:12:13 UTC
(In reply to Walter Bright from comment #1)
> Is the use of these intrinsics blockable with some macro?

I don't think so. They are not conditioned on a macro that could be simply (un)defined (if that's what you meant).
Comment 3 Walter Bright 2023-05-29 07:10:30 UTC
Could you please post the section of code in the windows.h you have?
Comment 4 Max Samukha 2023-06-03 06:53:11 UTC
Created attachment 1878 [details]
VC intrinsics referenced by windows.h
Comment 5 Max Samukha 2023-06-03 06:53:58 UTC
(In reply to Walter Bright from comment #3)
> Could you please post the section of code in the windows.h you have?

Please see an isolated test case in the attachment.
Comment 6 anonymous4 2023-12-01 10:26:40 UTC
Another problem is 

#define GENERIC_READ (0x80000000L)

these are interpreted as helper macros due to parentheses and skipped.
Comment 7 Walter Bright 2023-12-02 02:27:35 UTC
(In reply to anonymous4 from comment #6)
> Another problem is 
> 
> #define GENERIC_READ (0x80000000L)
> 
> these are interpreted as helper macros due to parentheses and skipped.

This PR should resolve that problem.

https://github.com/dlang/dmd/pull/15871
Comment 8 Carl Sturtivant 2024-03-11 05:49:19 UTC
Here's a workaround.
https://forum.dlang.org/post/lbvjpwqgcgducgoxwsxe@forum.dlang.org
There's a list of all x64 MSVC intrinsics at the included link with prototypes with named parameters.