Skip to content

Bindgen >=0.58 produces an invalid union with both packed and align representation hints  #2159

Open
@yutannihilation

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions