Skip to content

Unable to compile (or blacklist) typedef with union #1281

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

Closed
jgrund opened this issue Mar 23, 2018 · 4 comments
Closed

Unable to compile (or blacklist) typedef with union #1281

jgrund opened this issue Mar 23, 2018 · 4 comments
Assignees

Comments

@jgrund
Copy link

jgrund commented Mar 23, 2018

The following typedef does not compile on latest bindgen (0.33.2). Additionally there does not appear to be a way for me to ignore it and the error emitted. Bindings were able to be generated up to 0.30.0.

Input C/C++ Header

https://github.com/zfsonlinux/zfs/blob/387b6856d6d6997ae5849b8ad9155433fff6f077/include/sys/zfs_ioctl.h#L187-L333

Bindgen Invocation

    let bindings = bindgen::Builder::default()
        .header("wrapper.h")
        .header("/usr/src/zfs-0.7.7/include/sys/zfs_ioctl.h")
        .rustfmt_bindings(true)
        .blacklist_type("dmu_replay_record_t")
        .clang_arg("-I/usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/")
        .clang_arg("-I/usr/src/zfs-0.7.7/lib/libspl/include/")
        .clang_arg("-I/usr/src/zfs-0.7.7/include/")
        .generate()
        .expect("Unable to generate bindings");

Actual Results

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `ItemId(0)`,
 right: `ItemId(24198)`', /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/comp.rs:1295:21
stack backtrace:
   0: std::sys::unix::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:68
             at /checkout/src/libstd/sys_common/backtrace.rs:57
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:397
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:538
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: bindgen::ir::comp::CompInfo::from_ty::{{closure}}
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/comp.rs:1295
   8: bindgen::clang::visit_children
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/clang.rs:724
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: clang_visitChildren
  14: clang_sys::clang_visitChildren
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/clang-sys-0.22.0/src/link.rs:92
  15: bindgen::clang::Cursor::visit
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/clang.rs:398
  16: bindgen::ir::comp::CompInfo::from_ty
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/comp.rs:1186
  17: bindgen::ir::ty::Type::from_clang_ty
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/ty.rs:1147
  18: <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::from_ty_with_id
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/item.rs:1512
  19: <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::from_ty
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/item.rs:1413
  20: <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::parse
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/item.rs:1280
  21: bindgen::ir::comp::CompInfo::from_ty::{{closure}}
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/comp.rs:1293
  22: bindgen::clang::visit_children
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/clang.rs:724
  23: <unknown>
  24: <unknown>
  25: <unknown>
  26: <unknown>
  27: clang_visitChildren
  28: clang_sys::clang_visitChildren
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/clang-sys-0.22.0/src/link.rs:92
  29: bindgen::clang::Cursor::visit
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/clang.rs:398
  30: bindgen::ir::comp::CompInfo::from_ty
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/comp.rs:1186
  31: bindgen::ir::ty::Type::from_clang_ty
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/ty.rs:1147
  32: <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::from_ty_with_id
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/item.rs:1512
  33: <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::from_ty
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/item.rs:1413
  34: <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::parse
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/item.rs:1280
  35: bindgen::parse_one
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/lib.rs:1813
  36: bindgen::parse::{{closure}}::{{closure}}
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/lib.rs:1855
  37: bindgen::clang::visit_children
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/clang.rs:724
  38: <unknown>
  39: <unknown>
  40: <unknown>
  41: <unknown>
  42: clang_visitChildren
  43: clang_sys::clang_visitChildren
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/clang-sys-0.22.0/src/link.rs:92
  44: bindgen::clang::Cursor::visit
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/clang.rs:398
  45: bindgen::parse::{{closure}}
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/lib.rs:1855
  46: bindgen::ir::context::BindgenContext::with_module
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/ir/context.rs:2188
  47: bindgen::parse
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/lib.rs:1854
  48: bindgen::Bindings::generate
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/lib.rs:1651
  49: bindgen::Builder::generate
             at /root/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/bindgen-0.33.2/src/lib.rs:1104
  50: build_script_build::main
             at libzfs-sys/build.rs:18
  51: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  52: std::panicking::try::do_call
             at /checkout/src/libstd/rt.rs:59
             at /checkout/src/libstd/panicking.rs:480
  53: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:101
  54: std::rt::lang_start_internal
             at /checkout/src/libstd/panicking.rs:459
             at /checkout/src/libstd/panic.rs:365
             at /checkout/src/libstd/rt.rs:58
  55: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  56: main
  57: __libc_start_main
  58: <unknown>

Expected Results

Bindings to be generated.

@emilio
Copy link
Contributor

emilio commented Mar 23, 2018

Any chance you could use dump_preprocessed_input and creduce to generate a test-case?

See https://github.com/rust-lang-nursery/rust-bindgen/blob/6355f0a3dce637512b4ea279dbd4b1737fc46ce2/CONTRIBUTING.md#using-creduce-to-minimize-test-cases for instructions.

Thank you!

@emilio
Copy link
Contributor

emilio commented Mar 31, 2018

This is unrelated to the blacklisting, it's about this pattern of forward-declaring a struct and then defining it inside other semantic scope, which trips our assumptions. I think that assertion is just wrong.

@emilio
Copy link
Contributor

emilio commented Mar 31, 2018

Reduced test-case:

struct drr_begin;

struct dmu_replay_record {
  struct drr_begin {
    int foo;
  } u;
};

emilio added a commit to emilio/rust-bindgen that referenced this issue Mar 31, 2018
You can define a struct declared in an outer scope inside another struct.

C, what a language.

Fixes rust-lang#1281
emilio added a commit to emilio/rust-bindgen that referenced this issue Mar 31, 2018
You can define a struct declared in an outer scope inside another struct, and
the compiler won't even complain...

C, what a language.

Fixes rust-lang#1281
@emilio emilio self-assigned this Mar 31, 2018
bors-servo pushed a commit that referenced this issue Apr 2, 2018
ir: Remove an assertion that happens to be invalid.

You can define a struct declared in an outer scope inside another struct.

C, what a language.

Fixes #1281
@jgrund
Copy link
Author

jgrund commented Apr 8, 2018

Thanks! @emilio do you know when a there will be a new release with this fix included?

jeanphilippeD added a commit to jeanphilippeD/rust-bindgen that referenced this issue Aug 19, 2018
rustc fail to compile variadic function with ms_abi:
error[E0045]: variadic function must have C or cdecl calling convention

As suggested in issue, this short term fix: not generate binding
and emit a warning.

Fixes rust-lang#1281
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants