Closed
Description
Input C/C++ Header
#include <atomic>
struct StructWithAtomics
{
std::atomic<uint32_t> m_x;
uint32_t m_a, m_b, m_c;
};
StructWithAtomics frob();
Bindgen Invocation
$ bindgen foo.h --allowlist-function=frob --no-layout-tests -- -x c++
Actual Results
/* automatically generated by rust-bindgen 0.59.1 */
#[repr(C)]
#[derive(Debug)]
pub struct std_atomic<_Tp> {
pub _M_i: _Tp,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_Tp>>,
}
pub type std_atomic_value_type<_Tp> = _Tp;
pub type __uint32_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug)]
pub struct StructWithAtomics {
pub m_x: std_atomic<u32>,
pub m_a: u32,
pub m_b: u32,
pub m_c: u32,
}
extern "C" {
#[link_name = "\u{1}_Z4frobv"]
pub fn frob() -> StructWithAtomics;
}
With the System V AMD64 ABI (used on x86-64 pretty much everywhere except for Windows), this can actually create a calling convention mismatch because the bindings generated by Rust will expect StructWithAtomics
to be returned in RAX/RDX, whereas the C++ code will actually use a hidden return parameter. This can be demonstrated here: https://godbolt.org/z/4ErhEjb1v
Expected Results
/* automatically generated by rust-bindgen 0.59.1 */
#[repr(C)]
#[derive(Debug)]
pub struct StructWithAtomics {
pub m_x: std::sync::atomic::AtomicU32,
pub m_a: u32,
pub m_b: u32,
pub m_c: u32,
}
extern "C" {
#[link_name = "\u{1}_Z4frobv"]
pub fn frob() -> StructWithAtomics;
}
Metadata
Metadata
Assignees
Labels
No labels