Issue 24592 - ImportC: Bitfield layout wrong for int64 on 32-bit Linux
Summary: ImportC: Bitfield layout wrong for int64 on 32-bit Linux
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2024-06-09 14:21 UTC by Tim
Modified: 2024-06-17 00:31 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 Tim 2024-06-09 14:21:13 UTC
The followng struct from /usr/include/linux/perf_event.h has the wrong size with ImportC:
```
struct perf_branch_entry {
		__u64   from;
		__u64   to;
		__u64   mispred:1,  /* target mispredicted */
				predicted:1,/* target predicted */
				in_tx:1,    /* in transaction */
				abort:1,    /* transaction abort */
				cycles:16,  /* cycle count to last branch */
				type:4,     /* branch type */
				spec:2,     /* branch speculation info */
				new_type:4, /* additional branch type */
				priv:3,     /* privilege level */
				reserved:31;
};
```
With ImportC and dmd -m32 on Linux this has size 28, but with gcc -m32 it has size 24.

Found by comparing type sizes in druntime with type sizes found with ImportC: https://github.com/dlang/dmd/pull/16571
Comment 1 Dlang Bot 2024-06-16 17:00:42 UTC
@tim-dlang created dlang/dmd pull request #16590 "Fix bugzilla 24592 - ImportC: Bitfield layout wrong for int64 on 32-b…" fixing this issue:

- Fix bugzilla 24592 - ImportC: Bitfield layout wrong for int64 on 32-bit Linux
  
  Type ulong is 64-bit on 32-bit Linux, but has 32-bit alignment.
  This affects the layout of bitfields.
  
  Also add a new test for ImportC bitfields, which compares size,
  alignment and layout with the host C++ compiler. The existing
  tests compared with fixed values instead.

https://github.com/dlang/dmd/pull/16590
Comment 2 Dlang Bot 2024-06-17 00:31:09 UTC
dlang/dmd pull request #16590 "Fix bugzilla 24592 - ImportC: Bitfield layout wrong for int64 on 32-b…" was merged into master:

- e427ca656d801bcc438afce7fd6fba94d0e860c5 by Tim Schendekehl:
  Fix bugzilla 24592 - ImportC: Bitfield layout wrong for int64 on 32-bit Linux
  
  Type ulong is 64-bit on 32-bit Linux, but has 32-bit alignment.
  This affects the layout of bitfields.
  
  Also add a new test for ImportC bitfields, which compares size,
  alignment and layout with the host C++ compiler. The existing
  tests compared with fixed values instead.

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