Input C/C++ Header
typedef __SIZE_TYPE__ size_t;
Bindgen Invocation
# When using clang >= 21.1.0
bindgen input.h -- --target=m68k-unknown-linux-gnu
Actual Results
panicked at bindgen/codegen/mod.rs:946:25:
assertion `left == right` failed: Target platform requires `--no-size_t-is-usize`. The alignment of `size_t` (2) does not match the target pointer size (4)
left: 2
right: 4
Expected Results
This should produce an empty file without panicking.
Explanation
When the size_t_is_usize option is true, bindgen checks that size_t has the same underlying type as uintptr_t (see #1903). This check is implemented incorrectly as of bindgen 0.72.1.
For size_t to be same as uintptr_t, the types must have the same size and alignment. The actual check however asserts that the alignment of size_t is equal to the size of a pointer, not alignment.
|
assert_eq!( |
|
layout.align, |
|
ctx.target_pointer_size(), |
|
"Target platform requires `--no-size_t-is-usize`. The alignment of `{spelling}` ({}) does not match the target pointer size ({})", |
|
layout.align, |
|
ctx.target_pointer_size(), |
|
); |
This comes up on m68k because both size_t and uintptr_t have size 4 and alignment 2 on that architecture (though some Linux distros plan to change to a 4 byte alignment).
This bug is observable only when using clang 21.1.0 or newer, because the default alignment on m68k was changed in that release.
(This was discovered when porting linux-raw-sys to m68k.)
Input C/C++ Header
Bindgen Invocation
Actual Results
Expected Results
This should produce an empty file without panicking.
Explanation
When the
size_t_is_usizeoption is true, bindgen checks thatsize_thas the same underlying type asuintptr_t(see #1903). This check is implemented incorrectly as of bindgen 0.72.1.For
size_tto be same asuintptr_t, the types must have the same size and alignment. The actual check however asserts that the alignment ofsize_tis equal to the size of a pointer, not alignment.rust-bindgen/bindgen/codegen/mod.rs
Lines 996 to 1002 in 6bb8512
This comes up on m68k because both
size_tanduintptr_thave size 4 and alignment 2 on that architecture (though some Linux distros plan to change to a 4 byte alignment).This bug is observable only when using clang 21.1.0 or newer, because the default alignment on m68k was changed in that release.
(This was discovered when porting linux-raw-sys to m68k.)