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

Panic because of an invalid Ident #1464

Closed
nbrr opened this issue Dec 11, 2018 · 6 comments
Closed

Panic because of an invalid Ident #1464

nbrr opened this issue Dec 11, 2018 · 6 comments
Labels

Comments

@nbrr
Copy link

nbrr commented Dec 11, 2018

Input C/C++ Header

I'm trying to generate bindings from this library:
https://github.com/opensim-org/opensim-core/tree/master/

I'm sorry I am not sure what is expected there. My wrappe.hpp includes the headers from the Bindings directory of above mentioned library

#include <OpenSimHeaders_actuators.h>
#include <OpenSimHeaders_analyses.h>
#include <OpenSimHeaders_common.h>
#include <OpenSimHeaders_examplecomponents.h>
#include <OpenSimHeaders_simulation.h>
#include <OpenSimHeaders_tools.h>

I used dump_preprocessed_input in my build.rs that generated a 13MB __bindgen.ii, then I used this predicate.sh

#!/usr/bin/env bash
set -eu
/tmp/rust-bindgen/csmith-fuzzing/predicate.py \
    --expect-bindgen-fail \
    --bindgen-grep "thread 'main' panicked at '\"std___shared_count___shared_count<_Lp>\" is not a valid Ident'" \
    ./__bindgen.ii

and creduce ./predicate.sh ./__bindgen.ii gave me this, which I don't think is what was expected

(Interestingness test killed by timeout at 300 seconds.)
TERM caught, terminating 23114
 at /usr/bin/creduce line 35.
	main::__ANON__("TERM caught, terminating 23114\x{a}") called at /usr/bin/creduce line 1001
	main::sigHandler("TERM") called at /usr/bin/creduce line 308
	eval {...} called at /usr/bin/creduce line 308
	main::delta_test() called at /usr/bin/creduce line 326
	main::sanity_check() called at /usr/bin/creduce line 1067
 at /usr/bin/creduce line 35.
	main::__ANON__("TERM caught, terminating 23114\x{a} at /usr/bin/creduce line 35.\x{a}"...) called at /usr/bin/creduce line 308
	main::delta_test() called at /usr/bin/creduce line 326
	main::sanity_check() called at /usr/bin/creduce line 1067

Bindgen Invocation

    let bindings = bindgen::Builder::default()
        .header("wrapper.hpp")
        .clang_arg("-std=c++14")
        .clang_arg("-Iopensim-core/Bindings")
        .clang_arg("-Iopensim-core")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/SmallMatrix/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Scalar/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/BigMatrix/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Mechanics/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Simulation/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/Simbody/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Geometry/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Random/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Polynomial/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKmath/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKmath/Geometry/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKmath/Integrators/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/Simbody/Visualizer/include")
        .clang_arg("-Iopensim-core/Vendors/lepton/include")
        .clang_arg("-I/usr/lib/clang/7.0.0/include/")
        .generate()
        .expect("Unable to generate bindings");

Actual Results

$ RUST_BACKTRACE=1 cargo build
   Compiling try-opensim v0.1.0 (/home/nbrr/dev/bodysim/try-opensim)                                                                                                                                                                                                            
error: failed to run custom build command for `try-opensim v0.1.0 (/home/nbrr/dev/bodysim/try-opensim)`                                                                                                                                                                         
process didn't exit successfully: `/home/nbrr/dev/bodysim/try-opensim/target/debug/build/try-opensim-37f0c009d9c78e17/build-script-build` (exit code: 101)
--- stdout
cargo:rustc-link-lib=opensim

--- stderr
thread 'main' panicked at '"std___shared_count___shared_count<_Lp>" is not a valid Ident', /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/stable.rs:563:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:476
   5: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:390
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:345
   7: proc_macro2::stable::validate_term
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/stable.rs:563
   8: proc_macro2::stable::Ident::_new
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/stable.rs:495
   9: proc_macro2::stable::Ident::new
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/stable.rs:505
  10: proc_macro2::Ident::new
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.4.24/src/lib.rs:821
  11: bindgen::ir::context::BindgenContext::rust_ident_raw
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/ir/context.rs:937
  12: bindgen::ir::context::BindgenContext::rust_ident
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/ir/context.rs:929
  13: <bindgen::ir::function::Function as bindgen::codegen::CodeGenerator>::codegen
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:3424
  14: <bindgen::ir::item::Item as bindgen::codegen::CodeGenerator>::codegen
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:373
  15: <bindgen::ir::module::Module as bindgen::codegen::CodeGenerator>::codegen::{{closure}}
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:401
  16: <bindgen::ir::module::Module as bindgen::codegen::CodeGenerator>::codegen
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:431
  17: <bindgen::ir::item::Item as bindgen::codegen::CodeGenerator>::codegen
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:370
  18: <bindgen::ir::module::Module as bindgen::codegen::CodeGenerator>::codegen::{{closure}}
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:401
  19: <bindgen::ir::module::Module as bindgen::codegen::CodeGenerator>::codegen
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:431
  20: <bindgen::ir::item::Item as bindgen::codegen::CodeGenerator>::codegen
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:370
  21: bindgen::codegen::codegen::{{closure}}
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:3576
  22: bindgen::ir::context::BindgenContext::gen
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/ir/context.rs:1239
  23: bindgen::codegen::codegen
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/codegen/mod.rs:3554
  24: bindgen::Bindings::generate
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/lib.rs:1790
  25: bindgen::Builder::generate
             at /home/nbrr/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.44.0/src/lib.rs:1216
  26: build_script_build::main
             at ./build.rs:9
  27: std::rt::lang_start::{{closure}}
             at libstd/rt.rs:74
  28: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  29: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  30: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  31: std::rt::lang_start
             at libstd/rt.rs:74
  32: main
  33: __libc_start_main
  34: _start

Expected Results

That it works?

@emilio
Copy link
Contributor

emilio commented Dec 11, 2018

A reduced test-case would definitely be really helpful. Looks like creduce was timing out somehow, that's really weird.

In any case you can probably work around this marking the relevant type as opaque / blacklisted.

@emilio emilio added the bug label Dec 11, 2018
@nbrr
Copy link
Author

nbrr commented Dec 11, 2018

A reduced test-case would definitely be really helpful.

I have little understanding of how to do this. The help in the form here said to strip includes, but the library files seem to be full of includes. What am I supposed to provide?

In any case you can probably work around this marking the relevant type as opaque / blacklisted.

I have tried adding blacklist_type("shared_counter") to my buildgen invocation resulting in the same error. I don't know how to use this command/how to properly name the type. I think it comes from this file https://www.boost.org/doc/libs/1_62_0/boost/smart_ptr/detail/shared_count.hpp .

I also tried whitelist_type("PinJoint") to see what happens and it builds fine but the bindings.rs file is empty.

@emilio
Copy link
Contributor

emilio commented Dec 12, 2018

Ah, I see. Can you attach the whole .ii file somewhere? It'd be a start :)

Does blacklist_type(".*shared_count.*") help? It should I assume, it takes a regex so chances are that the call you posted isn't matching anything.

@nbrr
Copy link
Author

nbrr commented Dec 12, 2018

Does blacklist_type(".*shared_count.*") help? It should I assume, it takes a regex so chances are that the call you posted isn't matching anything.

I'm afraid this does not work either. Here's my full build.rs (with the blacklist line you suggested) in case I wrote something dumb.

extern crate bindgen;

use std::env;
use std::path::PathBuf;

fn main() {

    let bindings = bindgen::Builder::default()
        .blacklist_type(".*shared_count.*")
        .header("wrapper.hpp")
        .clang_arg("-std=c++14")
        .clang_arg("-Iopensim-core/Bindings")
        .clang_arg("-Iopensim-core")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/SmallMatrix/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Scalar/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/BigMatrix/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Mechanics/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Simulation/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/Simbody/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Geometry/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Random/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKcommon/Polynomial/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKmath/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKmath/Geometry/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/SimTKmath/Integrators/include")
        .clang_arg("-Iopensim-core/dependencies/simbody/Simbody/Visualizer/include")
        .clang_arg("-Iopensim-core/Vendors/lepton/include")
        .clang_arg("-I/usr/lib/clang/7.0.0/include/")
        .dump_preprocessed_input()
    //  .generate()
        .expect("Unable to generate bindings");

    // let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
    // bindings
    //     .write_to_file(out_path.join("bindings.rs"))
    //     .expect("Couldn't write bindings!");
}

Ah, I see. Can you attach the whole .ii file somewhere? It'd be a start :)

Here it is as a .txt file because github didn't like the .ii.
__bindgen.txt

@nbrr
Copy link
Author

nbrr commented Dec 22, 2018

Update.
Applying opaque to the whole std and whitelist to a few types works.

    let bindings = bindgen::Builder::default()
        .header("wrapper.hpp")
        .whitelist_type("OpenSim::PinJoint")
        .whitelist_type("OpenSim::Body")
        .opaque_type("std::.*")
        .clang_arg("-std=c++14")
// many clang_arg -I
        .generate()
        .expect("Unable to generate bindings");

blacklist, opaque, whitelist only don't work, blacklist+whitelist doesn't work.
I now run into a bunch of errors compiling the bindings but that would be for another time. They come from the headers made for SWIG so I might be able to get around these.

@emilio
Copy link
Contributor

emilio commented Feb 3, 2019

Reduced test-case:

template <int _Lp> class __shared_count {
public:
  __shared_count();
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants