Skip to content

Panic when dealing with values that hit ::MIN #244

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
dimbleby opened this issue Nov 13, 2016 · 3 comments
Closed

Panic when dealing with values that hit ::MIN #244

dimbleby opened this issue Nov 13, 2016 · 3 comments

Comments

@dimbleby
Copy link
Contributor

Eg if I add this to tests/headers/macro-expr-basic.h

#define FOOO (1 << 63)

then make tests/expectations/tests/macro-expr-basic.rs, then I hit:

./tests/tools/run-bindgen.py ./target/debug/bindgen tests/headers/macro-expr-basic.h tests/expectations/tests/macro-expr-basic.rs
run-bindgen.py: running ['./target/debug/bindgen', '-o', 'tests/expectations/tests/macro-expr-basic.rs', '--no-unstable-rust', '--raw-line', '', '--raw-line', '#![allow(non_snake_case)]', '--raw-line', '', 'tests/headers/macro-expr-basic.h']
thread 'main' panicked at 'attempt to negate with overflow', /data/build/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/aster-0.28.0/src/expr.rs:121
stack backtrace:
   1:     0x55a464f393cf - std::sys::backtrace::tracing::imp::write::h6f1d53a70916b90d
   2:     0x55a464f3e6ad - std::panicking::default_hook::{{closure}}::h137e876f7d3b5850
   3:     0x55a464f3d5ca - std::panicking::default_hook::h0ac3811ec7cee78c
   4:     0x55a464f3db68 - std::panicking::rust_panic_with_hook::hc303199e04562edf
   5:     0x55a464f3da02 - std::panicking::begin_panic::h6ed03353807cf54d
   6:     0x55a464f3d940 - std::panicking::begin_panic_fmt::hc321cece241bb2f5
   7:     0x55a464f3d8c1 - rust_begin_unwind
   8:     0x55a464f7520f - core::panicking::panic_fmt::h27224b181f9f037f
   9:     0x55a464f7513b - core::panicking::panic::h53676c30b3bd95eb
  10:     0x55a4647a90d4 - <aster::expr::ExprBuilder<F>>::int::h332f9c54bf4daf92
                        at /data/build/.cargo/registry/src/jiasu.xzqcsaa.nyc.mn-1ecc6299db9ec823/aster-0.28.0/src/expr.rs:121
  11:     0x55a46488b22f - <bindgen::ir::var::Var as bindgen::codegen::CodeGenerator>::codegen::h87eef49f9064993d
                        at /data/build/servo-bindgen/src/lib.rs:78
  12:     0x55a46488a9c1 - <bindgen::ir::item::Item as bindgen::codegen::CodeGenerator>::codegen::h04435fa45868eaf8
                        at /data/build/servo-bindgen/src/lib.rs:78
  13:     0x55a4648c7c11 - bindgen::codegen::codegen::{{closure}}::hfd5e688be75c6e21
                        at /data/build/servo-bindgen/src/lib.rs:78
  14:     0x55a464868609 - bindgen::ir::context::BindgenContext::gen::h1f950da8d173fcfa
                        at /data/build/servo-bindgen/src/ir/context.rs:404
  15:     0x55a4648aeddb - bindgen::codegen::codegen::h91f710e7aef65137
                        at /data/build/servo-bindgen/src/lib.rs:78
  16:     0x55a464881b5e - bindgen::Bindings::generate::ha28a5bb5b9d1e04a
                        at /data/build/servo-bindgen/src/lib.rs:440
  17:     0x55a464881385 - bindgen::Builder::generate::hf9727ae19cc2ecf9
                        at /data/build/servo-bindgen/src/lib.rs:276
  18:     0x55a4646253cb - bindgen::main::hfbf366f81761df92
                        at /data/build/servo-bindgen/src/bin/bindgen.rs:75
  19:     0x55a464f46176 - __rust_maybe_catch_panic
  20:     0x55a464f3ce41 - std::rt::lang_start::h538f8960e7644c80
  21:     0x55a464627653 - main
  22:     0x7f322ba00730 - __libc_start_main
  23:     0x55a4645b17c8 - _start
  24:                0x0 - <unknown>
Traceback (most recent call last):
  File "./tests/tools/run-bindgen.py", line 175, in <module>
    main()
  File "./tests/tools/run-bindgen.py", line 170, in main
    args.rust_bindings)
  File "./tests/tools/run-bindgen.py", line 132, in generate_bindings
    run_cmd(command, cwd=os.getcwd(), env=make_bindgen_env())
  File "./tests/tools/run-bindgen.py", line 123, in run_cmd
    subprocess.check_call(command, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 541, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['./target/debug/bindgen', '-o', 'tests/expectations/tests/macro-expr-basic.rs', '--no-unstable-rust', '--raw-line', '', '--raw-line', '#![allow(non_snake_case)]', '--raw-line', '', 'tests/headers/macro-expr-basic.h']' returned non-zero exit status 101
Makefile:29: recipe for target 'tests/expectations/tests/macro-expr-basic.rs' failed
make: *** [tests/expectations/tests/macro-expr-basic.rs] Error 1

(I hit this with a real header file.)

@emilio
Copy link
Contributor

emilio commented Nov 13, 2016

Yikes, thanks for filling this, quick fix incoming, and I guess I'll fix it properly on aster too.

Keep them coming! :)

@emilio
Copy link
Contributor

emilio commented Nov 13, 2016

Fixed with #245, and in aster in serde-deprecated/aster#122. Though I guess I'll also special-case macros to be unsigned if they're generating a number with only one bit?

@emilio
Copy link
Contributor

emilio commented Nov 16, 2016

This is fixed in bindgen now, thanks again for reporting it! :)

@emilio emilio closed this as completed Nov 16, 2016
luser pushed a commit to luser/rust-bindgen that referenced this issue Mar 27, 2017
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