D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22756 - ImportC: no __builtin_offsetof
Summary: ImportC: no __builtin_offsetof
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: ImportC, pull
Depends on:
Blocks:
 
Reported: 2022-02-10 10:47 UTC by dave287091
Modified: 2022-02-17 13:16 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description dave287091 2022-02-10 10:47:09 UTC
C11 defines a standard macro `offsetof` (which is defined in 7.19 in the definition of what is in the <stddef.h> header). Clang implements this with a compiler intrinsic `__builtin_offsetof`. I can’t find a clang reference, but it just does what the macro would do.

 The following C code:

// off.c
#include <stddef.h>
struct Foo {    int x;
};
int y = offsetof(struct Foo, x)

Expands to:

// off.i
struct Foo {
    int x; };  

int y = __builtin_offsetof(struct Foo, x);

which dmd rejects, as it can’t handle the __builtin_offsetof.

The above is the simplest case, the following is also allowed:

struct Foo {
    struct {
        int x;
    } y;
};
int y = __builtin_offsetof(struct Foo, y.x);
Comment 1 Dlang Bot 2022-02-11 09:03:18 UTC
@WalterBright updated dlang/druntime pull request #3736 "fix Issue 22756 - ImportC: no __builtin_offsetof" fixing this issue:

- fix Issue 22756 - ImportC: no __builtin_offsetof

https://github.com/dlang/druntime/pull/3736
Comment 2 Dlang Bot 2022-02-11 10:14:26 UTC
dlang/druntime pull request #3736 "fix Issue 22756 - ImportC: no __builtin_offsetof" was merged into master:

- cd85cb0bbf4674d774e88161cdbbd70422aaacbd by Walter Bright:
  fix Issue 22756 - ImportC: no __builtin_offsetof

https://github.com/dlang/druntime/pull/3736
Comment 3 dave287091 2022-02-11 18:33:18 UTC
The above PR defines a “__builtin_offset”, not a “__builtin_offsetof”.
Comment 4 Dlang Bot 2022-02-12 07:23:03 UTC
@WalterBright created dlang/druntime pull request #3739 "fix Issue 22756 - ImportC: no __builtin_offsetof" fixing this issue:

- fix Issue 22756 - ImportC: no __builtin_offsetof

https://github.com/dlang/druntime/pull/3739
Comment 5 Dlang Bot 2022-02-17 13:16:48 UTC
dlang/druntime pull request #3739 "fix Issue 22756 - ImportC: no __builtin_offsetof" was merged into master:

- b917bc143c58485ade6dbad5ca0dd6e8efd74bf5 by Walter Bright:
  fix Issue 22756 - ImportC: no __builtin_offsetof

https://github.com/dlang/druntime/pull/3739