Issue 23614 - ImportC: __int128 not supported
Summary: ImportC: __int128 not supported
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Mac OS X
: P1 blocker
Assignee: No Owner
URL:
Keywords: ImportC, pull
Depends on:
Blocks:
 
Reported: 2023-01-09 17:55 UTC by Jacob Carlborg
Modified: 2023-01-14 14:39 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jacob Carlborg 2023-01-09 17:55:14 UTC
Compiling the following C code:

unsigned long long _mulx_u64(unsigned long long __X, unsigned long long __Y, unsigned long long *__P)
{
    unsigned __int128 __res = (unsigned __int128) __X * __Y;
    *__P = (unsigned long long) (__res >> 64);
    return (unsigned long long) __res;
}


Results in the following errors:

foo.c(3): Error: missing comma or semicolon after declaration of `extern ()`, found `__res` instead

I'm using macOS 13.0.1, DMD v2.101.1 and Xcode 14.2.
Comment 1 Walter Bright 2023-01-09 21:11:51 UTC
At least a better error message:

https://github.com/dlang/dmd/pull/14797
Comment 2 Walter Bright 2023-01-09 21:13:05 UTC
Do you really need this function, or is it just something in the header? Does the header have an #if alternative path in it?
Comment 3 Jacob Carlborg 2023-01-10 06:35:02 UTC
(In reply to Walter Bright from comment #2)
> Do you really need this function, or is it just something in the header?
> Does the header have an #if alternative path in it?

No, I see now that it's guarded with __SIZEOF_INT128__. Adding `#undef __SIZEOF_INT128__` in "importc.h" works.
Comment 4 Jacob Carlborg 2023-01-10 06:37:07 UTC
Here's the full preprocessor logic:

#if !defined BR_INT128 && !defined BR_UMUL128
#ifdef __SIZEOF_INT128__
#define BR_INT128    1
#elif _M_X64
#define BR_UMUL128   1
#endif
#endif

Then rest of the code checks for "BR_INT128" and "BR_UMUL128". Perhaps "_M_X64" should be undefined as well.
Comment 5 Jacob Carlborg 2023-01-10 06:41:50 UTC
(In reply to Jacob Carlborg from comment #4)
> Here's the full preprocessor logic:
> 
> #if !defined BR_INT128 && !defined BR_UMUL128
> #ifdef __SIZEOF_INT128__
> #define BR_INT128    1
> #elif _M_X64
> #define BR_UMUL128   1
> #endif
> #endif
> 
> Then rest of the code checks for "BR_INT128" and "BR_UMUL128". Perhaps
> "_M_X64" should be undefined as well.

It's available here [1]. I'm trying to compile BearSSL [2]. I'm just running DMD on the files in the "src" directory and reporting issues as I find them.

It's quite a bit problematic that the Clang preprocessor is used, which supports a bunch of extensions that DMD doesn't support.

[1] https://bearssl.org/gitweb/?p=BearSSL;a=blob;f=src/inner.h;h=07e1d0a478e801a91580658918130fb8b595e407;hb=HEAD#l403

[2] https://bearssl.org/#download-and-installation
Comment 6 Walter Bright 2023-01-12 02:00:04 UTC
Thanks, this is what I need to know.
Comment 7 Dlang Bot 2023-01-12 02:10:50 UTC
@WalterBright created dlang/dmd pull request #14805 "fix Issue 23614 - ImportC: __int128 not supported" fixing this issue:

- fix Issue 23614 - ImportC: __int128 not supported

https://github.com/dlang/dmd/pull/14805
Comment 8 Dlang Bot 2023-01-14 12:17:45 UTC
dlang/dmd pull request #14805 "fix Issue 23614 - ImportC: __int128 not supported" was merged into stable:

- 2e02e183729d6648130b4fbcbf73b64f5d5cd080 by Walter Bright:
  fix Issue 23614 - ImportC: __int128 not supported

https://github.com/dlang/dmd/pull/14805
Comment 9 Dlang Bot 2023-01-14 14:39:44 UTC
dlang/dmd pull request #14815 "Merge stable" was merged into master:

- ee3176917dc4edc466ce10676f1f8336267341ba by Walter Bright:
  fix Issue 23614 - ImportC: __int128 not supported (#14805)

https://github.com/dlang/dmd/pull/14815