Bug 24094 – importC __declspec not working in front of declaration statement

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-08-20T03:10:20Z
Last change time
2023-11-02T06:56:36Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Michael Barth

Comments

Comment #0 by spirrwell — 2023-08-20T03:10:20Z
Hello! I've tried compiling both nuklear and stb_image using importC which are single-header libraries. This leads to some errors in corecrt_malloc.h (in the UCRT for Windows/MSVC) that appear to perhaps be related to unsupported declspec things. For a simple reproduction, all that is necessary is to create a C file that includes stdlib.h and compile it with DMD. Here are some of the errors: C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_malloc.h(58): Error: extended-decl-modifier expected C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_malloc.h(58): Error: no type for declarator before `)` C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_malloc.h(65): Error: extended-decl-modifier expected C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_malloc.h(65): Error: no type for declarator before `)` Which that code looks something like this: _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size) _ACRTIMP _CRTALLOCATOR _CRTRESTRICT void* __cdecl _calloc_base( _In_ size_t _Count, _In_ size_t _Size ); _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size) _ACRTIMP _CRT_JIT_INTRINSIC _CRTALLOCATOR _CRTRESTRICT _CRT_HYBRIDPATCHABLE void* __cdecl calloc( _In_ _CRT_GUARDOVERFLOW size_t _Count, _In_ _CRT_GUARDOVERFLOW size_t _Size ); Which after preprocessing might look like this: __declspec(allocator) __declspec(restrict) void* __cdecl _calloc_base( size_t _Count, size_t _Size ); In talking with some folks on Discord about a month ago, it sounded like people thought it was either due to the allocator or restrict declspecs here and that they should be able to be safely ignored.
Comment #1 by bugzilla — 2023-08-22T02:29:13Z
I tried the following: ------------ test.c ----------- __declspec(allocator) __declspec(restrict) void* __cdecl _calloc_base(int, int); ------------------------------- and it compiled without error. Can you perhaps try your code with the latest compiler? I note that __declspec(restrict) was a newer addition to dmd.
Comment #2 by spirrwell — 2023-08-25T01:43:26Z
(In reply to Walter Bright from comment #1) > I tried the following: > > ------------ test.c ----------- > __declspec(allocator) __declspec(restrict) > void* __cdecl _calloc_base(int, int); > ------------------------------- > > and it compiled without error. Can you perhaps try your code with the latest > compiler? I note that __declspec(restrict) was a newer addition to dmd. Hm, my bad. I guess I was literally just a few versions behind. It does compile with the latest DMD. It looks like it also compiles with the latest beta version of LDC2 as well. There is one more __declspec issue I've come across that is still present as of DMD v2.105.0. Error: found `__declspec` instead of statement This error seems to happen with the following code: void fun() { __declspec(align(16)) short data[64]; } This does not happen if the variable is in global scope or part of a struct. As far as I've tested, it only occurs if the variable is declared inside a function body.
Comment #3 by dlang-bot — 2023-11-02T05:45:18Z
@WalterBright created dlang/dmd pull request #15773 "fix Issue 24094 - importC __declspec not working in front of declarat…" fixing this issue: - fix Issue 24094 - importC __declspec not working in front of declaration statement https://github.com/dlang/dmd/pull/15773
Comment #4 by dlang-bot — 2023-11-02T06:56:36Z
dlang/dmd pull request #15773 "fix Issue 24094 - importC __declspec not working in front of declarat…" was merged into master: - 77ce3096cbebdf6f436a50973ab254118f3e18a5 by Walter Bright: fix Issue 24094 - importC __declspec not working in front of declaration statement https://github.com/dlang/dmd/pull/15773