rust-lang / rust-lang/rust-bindgen

Thread 'bindgen_test_layout_header' panicked at 'assertion failed: `(left == right)`

Open
#943 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-spe bug I-bogus-codegen I-failing-layout-test
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

I am using this script (https://gist.github.com/fitzgen/187381e358f60efa8194d0b276b4d11a) for testing.
The hashtag for my bindgen version is e841f6f88d13298.

$ ./b.sh bindgen abc.h

clang-4.0: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
abc.h:6:19: warning: unknown attribute 'size' ignored [-Wunknown-attributes]
} __attribute__ ((size, packed));
                  ^
1 warning generated.
abc.h:6:19: warning: unknown attribute 'size' ignored [-Wunknown-attributes], err: false

running 1 test
test bindgen_test_layout_header ... FAILED

failures:

---- bindgen_test_layout_header stdout ----
        thread 'bindgen_test_layout_header' panicked at 'assertion failed: `(left == right)`
  left: `5`,
 right: `8`: Size of: header', /tmp/bindings-hJzMPE.rs:46:4
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:380
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:390
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:611
   5: std::panicking::begin_panic_new
             at /checkout/src/libstd/panicking.rs:553
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:521
   7: bindings_hJzMPE::bindgen_test_layout_header
   8: <F as test::FnBox<T>>::call_box
             at /checkout/src/libtest/lib.rs:1477
             at /checkout/src/libcore/ops/function.rs:143
             at /checkout/src/libtest/lib.rs:138
   9: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:98


failures:
    bindgen_test_layout_header

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

Interesting: bindgen emitted type definitions that are failing their
layout unit tests!

$ cat abc.h

struct header
{
  char proto;
  unsigned int size __attribute__ ((packed));
  unsigned char data[] __attribute__ ((aligned (8)));
} __attribute__ ((size, packed));

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the testing script in the linked gist and the abc.h reproducer, then run ./b.sh bindgen abc.h with the reported bindgen revision. Inspect the generated bindings and bindgen_test_layout_header failure, comparing the emitted Rust layout assertions with the C struct layout. Done means the reproducer generates bindings whose layout tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.