Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csmith: pragma pack(1) have no effect #1074

Closed
pepyakin opened this issue Oct 11, 2017 · 1 comment
Closed

csmith: pragma pack(1) have no effect #1074

pepyakin opened this issue Oct 11, 2017 · 1 comment

Comments

@pepyakin
Copy link
Contributor

Input C/C++ Header

#include "csmith.h"
#pragma pack(1)
struct S0 {
  int64_t a;
  uint32_t b
};

Bindgen Invocation

Predicate invocation:

predicate.py \
    --bindings-grep "S0" \
    --expect-layout-tests-fail \
    --layout-tests-grep "Size of\: S0" \
    ./header.h

(bindgen args)

Actual Results

Layout test panics:

	thread 'bindgen_test_layout_S0' panicked at 'assertion failed: `(left == right)`
  left: `16`,
 right: `12`: Size of: S0', /var/folders/cd/c9707gm91qj22fkb99clygfm0000gn/T/bindings-_cv07rmk.rs:3:245
stack backtrace:
   0:        0x108977193 - std::sys::imp::backtrace::tracing::imp::unwind_backtrace::h5d6b821bcccc8af3
   1:        0x108978f2a - std::panicking::default_hook::{{closure}}::haca53f8b96e15b81
   2:        0x108978a28 - std::panicking::default_hook::h0029f59c1ec97ffc
   3:        0x10897b1f2 - std::panicking::rust_panic_with_hook::hb8eae939c3fcaf9c
   4:        0x10897b054 - std::panicking::begin_panic_new::h3c5f9a0be81106be
   5:        0x10897afa2 - std::panicking::begin_panic_fmt::hf585b6224c51a06c
   6:        0x108933626 - bindings__cv07rmk::bindgen_test_layout_S0::h6d23c0f174ff34f5
   7:        0x108944561 - <F as test::FnBox<T>>::call_box::h88fe84a510dab8dd
   8:        0x10897c34c - __rust_maybe_catch_panic
   9:        0x108934f88 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb43ec92c3523e599
  10:        0x108935d67 - std::panicking::try::do_call::h8a550a9232e81176
  11:        0x10897c34c - __rust_maybe_catch_panic
  12:        0x10893dec3 - <F as alloc::boxed::FnBox<A>>::call_box::hacbca7a24de7f7d5
  13:        0x1089784cb - std::sys::imp::thread::Thread::new::thread_start::h823686b907c11c46
  14:     0x7fffd586493a - _pthread_body
  15:     0x7fffd5864886 - _pthread_start


failures:
    bindgen_test_layout_S0

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

Generated bindings:

/* automatically generated by rust-bindgen */

#[repr(C)]
#[derive(Debug, Copy)]
pub struct S0 {
    pub a: ::std::os::raw::c_longlong,
    pub b: ::std::os::raw::c_uint,
}
#[test]
fn bindgen_test_layout_S0() {
    assert_eq!(
        ::std::mem::size_of::<S0>(),
        12usize,
        concat!("Size of: ", stringify!(S0))
    );
    assert_eq!(
        ::std::mem::align_of::<S0>(),
        1usize,
        concat!("Alignment of ", stringify!(S0))
    );
    assert_eq!(
        unsafe { &(*(0 as *const S0)).a as *const _ as usize },
        0usize,
        concat!("Alignment of field: ", stringify!(S0), "::", stringify!(a))
    );
    assert_eq!(
        unsafe { &(*(0 as *const S0)).b as *const _ as usize },
        8usize,
        concat!("Alignment of field: ", stringify!(S0), "::", stringify!(b))
    );
}
impl Clone for S0 {
    fn clone(&self) -> Self {
        *self
    }
}

Expected Results

it seems #pragma pack(1) has no effect, because rust itself doesn't support repr(packed).

@pepyakin
Copy link
Contributor Author

Duplicate of #537

@pepyakin pepyakin marked this as a duplicate of #537 Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant