Skip to content

Opaque structs not generating with right size #3177

Open
@leon-xd

Description

@leon-xd

Hello bindgen team! I am having some issues with bindings generated from Windows USB headers defined in ucxusbdevice.h. Here is a link to a minimal repro I've been able to generate: https://github.com/leon-xd/rust-repros/tree/main/crates/bindgen-size-overflow. I copied relevant definitions and made a new header file that is able to reproduce the issue.

There are four structs that are not generated with the right definition. It seems like they are generated as opaque, but do not have the correct size. In switching from bindgen 0.69.* to 0.71.0 we were able to detect this issue with the introduction of compile time error checking.

A (preferably reduced) C/C++ header file that reproduces the issue

The bindgen flags used to reproduce the issue with the header file

The expected bindgen output

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _USBDEVICE_ABORTIO {
    pub _address: _USBDEVICE_MGMT_HEADER,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of _USBDEVICE_ABORTIO"][::std::mem::size_of::<_USBDEVICE_ABORTIO>() - 24usize];
    ["Alignment of _USBDEVICE_ABORTIO"][::std::mem::align_of::<_USBDEVICE_ABORTIO>() - 8usize];
};

The actual bindgen output

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _USBDEVICE_ABORTIO {
    pub _address: u8,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of _USBDEVICE_ABORTIO"][::std::mem::size_of::<_USBDEVICE_ABORTIO>() - 24usize];
    ["Alignment of _USBDEVICE_ABORTIO"][::std::mem::align_of::<_USBDEVICE_ABORTIO>() - 8usize];
};

The debugging logs generated when running bindgen on this testcase

  • The output of cargo build -vvv is here: logs.txt

Metadata

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