rust-lang / rust-lang/rust-bindgen
Can get vtables wrong when inheriting from a template type parameter
Open
Nobody has claimed this yet.
A-C++
A-templates
I-failing-layout-test
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Input C/C++ Header
// bindgen-flags: --enable-cxx-namespaces -- -std=c++14
template<typename T>
struct DerivedMaybeHasVtable : public T {
public:
int x;
};
struct BaseWithVtable {
int y;
virtual void hello();
};
struct BaseWithoutVtable {
int z;
void hello();
};
static DerivedMaybeHasVtable<BaseWithVtable> YES_VTABLE;
static DerivedMaybeHasVtable<BaseWithoutVtable> NO_VTABLE;
Actual Results
running 4 tests
test root::bindgen_test_layout_BaseWithVtable ... ok
test root::__bindgen_test_layout_DerivedMaybeHasVtable_open0_BaseWithoutVtable_close0_instantiation ... ok
test root::bindgen_test_layout_BaseWithoutVtable ... ok
test root::__bindgen_test_layout_DerivedMaybeHasVtable_open0_BaseWithVtable_close0_instantiation ... FAILED
failures:
---- root::__bindgen_test_layout_DerivedMaybeHasVtable_open0_BaseWithVtable_close0_instantiation stdout ----
thread 'root::__bindgen_test_layout_DerivedMaybeHasVtable_open0_BaseWithVtable_close0_instantiation' panicked at 'assertion failed: `(left == right)`
left: `24`,
right: `16`: Size of template specialization: root :: DerivedMaybeHasVtable < root :: BaseWithVtable >', /tmp/bindings.rs.KLHxFQ:83:8
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: bindgen_test_one::root::__bindgen_test_layout_DerivedMaybeHasVtable_open0_BaseWithVtable_close0_instantiation
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:
root::__bindgen_test_layout_DerivedMaybeHasVtable_open0_BaseWithVtable_close0_instantiation
test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
Expected Results
We figure out how to support types that may or may not have a vtable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with the provided C++14 header and bindgen flags, then inspect the layout-test generation and C++ inheritance/vtable handling involved in the failing specialization. Done means the generated layout tests correctly handle both the vtable-bearing and non-vtable template instantiations without regressing the passing cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100