rust-lang / rust-lang/rust-bindgen
Bindgen >=0.58 produces an invalid union with both packed and align representation hints
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
I tried to bump the version, but found this error on Windows with cross-compilation.
Input C/C++ Header
#include <math.h>
or
#define _CRT_PACKING 8
#pragma pack(push,_CRT_PACKING)
typedef union __mingw_ldbl_type_t
{
long double x;
struct {
unsigned int low, high;
int sign_exponent : 16;
int res1 : 16;
int res0 : 32;
} lh;
} __mingw_ldbl_type_t;
Bindgen Invocation
cargo +stable-msvc build --target x86_64-pc-windows-gnu
bindgen::Builder::default()
.header("input.h")
.generate()
.unwrap()
Actual Results
error[E0587]: type has conflicting packed and align representation hints
--> C:\Users\Yutani\Documents\GitHub\libR-sys\target\x86_64-pc-windows-gnu\debug\build\libR-sys-4d11865a7eb8fac8\out/bindings.rs:747:1
|
747 | / pub union __mingw_ldbl_type_t {
748 | | pub x: u128,
749 | | pub lh: __mingw_ldbl_type_t__bindgen_ty_1,
750 | | }
| |_^
For more information about this error, try `rustc --explain E0587`.
error: could not compile `libR-sys` due to previous error
The diff between bindgen 0.57 and 0.58:
#[repr(C, packed(8))]
+ #[repr(align(8))]
#[derive(Copy, Clone)]
pub union __mingw_ldbl_type_t {
pub x: u128,
pub lh: __mingw_ldbl_type_t__bindgen_ty_1,
- _bindgen_union_align: [u64; 2usize],
}
Expected Results
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the shown C/C++ headers and bindgen invocation, then inspect the generated bindings around __mingw_ldbl_type_t and compare the 0.57 and 0.58 output. Trace how bindgen chooses the union's packed and align representation hints; done means the generated Rust no longer contains conflicting hints and the Windows cross-compilation succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100