Skip to content

Linking to wrong overloaded virtual destructor #1133

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
not-fl3 opened this issue Nov 1, 2017 · 1 comment
Closed

Linking to wrong overloaded virtual destructor #1133

not-fl3 opened this issue Nov 1, 2017 · 1 comment

Comments

@not-fl3
Copy link

not-fl3 commented Nov 1, 2017

Input C/C++ Header

struct A {
    virtual ~A() = 0;
};

struct B : A {
    B() {}
    ~B();
};

Here is origianl source file and entire project, just in case: https://github.com/not-fl3/test-sys/blob/destructor/test.hpp

Bindgen Invocation

$ bindgen test.hpp --generate-inline-functions

Actual Results

Bindgen's generated code:

#[link_name = "\u{1}_ZN1BD0Ev"]
pub fn B_B_destructor(this: *mut B);

And here is rust test case:

#[test()]
fn create_delete_test() {
    unsafe {
        let mut a = test::B::new();
        test::B_B_destructor(&mut a as *mut _);
    }
}

Its the test because for some reason the error appears only from tests.
cargo test --verbose ouput:

running 3 tests
~B
~A
test create_delete_test ... ok
test test::bindgen_test_layout_A ... ok
error: process didn't exit successfully: `/home/fl3/fun/test-sys/target/debug/deps/test_sys-b31f0fc43306b593` (signal: 11, SIGSEGV: invalid memory reference)

And it works pretty fine with ZN1BD1Ev instead of ZN1BD0Ev.

Expected Results

I think, that in that case bindgen should links with ZN1BD1Ev for destructor. ZN1BD0Ev is virtual deleting destructor, and trys to delete rust-allocated memory.

@emilio
Copy link
Contributor

emilio commented Jan 29, 2018

Thanks for the report, and sorry for the huge lag to get to this. Fix at #1240.

Thanks again!

bors-servo pushed a commit that referenced this issue Jan 29, 2018
ir: Choose the right mangling for destructors on all codepaths.

Fixes #1133.
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

3 participants