D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22955 - importC: wrong alignof for D struct with specified alignment
Summary: importC: wrong alignof for D struct with specified alignment
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-03-29 15:18 UTC by duser
Modified: 2022-03-31 08:13 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 duser 2022-03-29 15:18:14 UTC
using the "align (16) struct __uint128_t" struct from __builtins.di:

_Static_assert( _Alignof(__uint128_t) == 16, "" ); // fail

it gives the size of a pointer (4 or 8), same as if align() wasn't used


it has the correct alignment in D:

import __builtins;
pragma(msg, __uint128_t.alignof); // 16


_Alignas() in C doesn't have the problem:

struct S { _Alignas(16) unsigned long long a; unsigned long long b; };
_Static_assert( _Alignof(struct S) == 16, "this works" );
_Static_assert( sizeof(struct S) == 16, "this works" );
Comment 1 Dlang Bot 2022-03-31 02:48:46 UTC
@WalterBright created dlang/dmd pull request #13930 "fix Issue 22955 - importC: wrong alignof for D struct with specified …" fixing this issue:

- fix Issue 22955 - importC: wrong alignof for D struct with specified alignment

https://github.com/dlang/dmd/pull/13930
Comment 2 Dlang Bot 2022-03-31 08:13:27 UTC
dlang/dmd pull request #13930 "fix Issue 22955 - importC: wrong alignof for D struct with specified …" was merged into master:

- c02a98152928993e42ad9356b1c27817846ad76c by Walter Bright:
  fix Issue 22955 - importC: wrong alignof for D struct with specified alignment

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