Bug 22721 – importC: some gnu builtins are rejected

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-01-31T22:14:48Z
Last change time
2022-07-09T22:13:23Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
dave287091

Comments

Comment #0 by dave287091 — 2022-01-31T22:14:48Z
Trying to compile CoreFoundation.h on macOS has led me to encounter the following builtins, which are documented here: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html __builtin_bswap32 __builtin_bswap64 __builtin_constant_p __builtin_expect __builtin_assume The last 3 are just optimization hints.
Comment #1 by bugzilla — 2022-02-02T09:31:27Z
This will have to wait for: https://github.com/dlang/druntime/pull/3702 to get merged.
Comment #2 by dlang-bot — 2022-02-03T18:45:29Z
dlang/druntime pull request #3720 "fix Issue 22721 - importC: some gnu builtins are rejected" was merged into master: - 77101360cbf65040dd7cbb151027c7995c5bc6a1 by Walter Bright: fix Issue 22721 - importC: some gnu builtins are rejected https://github.com/dlang/druntime/pull/3720
Comment #3 by duser — 2022-02-08T18:02:16Z
slight issue with the fix: "__builtin_assume_aligned" in the linked GNU docs is different from the "__builtin_assume" mentioned in the issue, the actual one is documented here: https://releases.llvm.org/13.0.0/tools/clang/docs/LanguageExtensions.html#builtin-assume its D implementation would be void __builtin_assume()(lazy bool) { return; } the assume builtin added in the PR has the signature of __builtin_assume_aligned from the docs but is named __builtin_assume, it should be renamed to add _aligned
Comment #4 by duser — 2022-02-08T18:04:46Z
also, __builtin_expect in the PR is using the D long type but should probably use c_long
Comment #5 by dave287091 — 2022-02-08T18:34:52Z
(In reply to duser from comment #3) > slight issue with the fix: > > "__builtin_assume_aligned" in the linked GNU docs is different from the > "__builtin_assume" mentioned in the issue, the actual one is documented here: > > https://releases.llvm.org/13.0.0/tools/clang/docs/LanguageExtensions. > html#builtin-assume > > its D implementation would be > > void __builtin_assume()(lazy bool) { return; } > > the assume builtin added in the PR has the signature of > __builtin_assume_aligned > from the docs but is named __builtin_assume, it should be renamed to add > _aligned __builtin_assume is a clang extension, which I don’t think GCC has. https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/Builtins.def#L1550. It is present in at least <dispatch/dispatch.h> on macOS.
Comment #6 by bugzilla — 2022-02-10T06:32:08Z
I fixed this with a macro, as there's no way to tell dmd to not evaluate `arg`. https://github.com/dlang/druntime/pull/3730
Comment #7 by bugzilla — 2022-02-10T06:47:48Z
(In reply to Walter Bright from comment #6) > I fixed this with a macro, as there's no way to tell dmd to not evaluate > `arg`. I found a way - make the parameter lazy.
Comment #8 by dlang-bot — 2022-02-10T06:49:34Z
@WalterBright created dlang/druntime pull request #3734 "fix Issue 22721 - importC: some gnu builtins are rejected" fixing this issue: - fix Issue 22721 - importC: some gnu builtins are rejected https://github.com/dlang/druntime/pull/3734
Comment #9 by dlang-bot — 2022-02-10T07:48:57Z
dlang/druntime pull request #3734 "fix Issue 22721 - importC: some gnu and clang builtins are rejected" was merged into master: - d31ad8004c1d8674979a8103d218bd9cd2dc3c22 by Walter Bright: fix Issue 22721 - importC: some gnu and clang builtins are rejected https://github.com/dlang/druntime/pull/3734
Comment #10 by dlang-bot — 2022-07-09T22:13:23Z
dlang/dmd pull request #14281 "[project] Merge druntime into the dmd repository" was merged into master: - f9a44c3a3cb47c5604db1a34b821a3b0e679b8b8 by Walter Bright: fix Issue 22721 - importC: some gnu builtins are rejected https://github.com/dlang/dmd/pull/14281