Skip to content

Commit 9798d92

Browse files
committed
codegen: Properly handle virtual bases.
1 parent 6720a99 commit 9798d92

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

libbindgen/src/codegen/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,14 +835,18 @@ impl CodeGenerator for CompInfo {
835835
}
836836

837837
for (i, base) in self.base_members().iter().enumerate() {
838+
// Virtual bases are already taken into account by the vtable
839+
// pointer.
840+
//
841+
// FIXME(emilio): Is this always right?
842+
if base.is_virtual() {
843+
continue;
844+
}
845+
838846
let base_ty = ctx.resolve_type(base.ty);
839847
// NB: We won't include unsized types in our base chain because they
840848
// would contribute to our size given the dummy field we insert for
841849
// unsized types.
842-
//
843-
// NB: Canonical type is here because it could be inheriting from a
844-
// typedef, for example, and the lack of `unwrap()` is because we
845-
// can inherit from a template parameter, yes.
846850
if base_ty.is_unsized(ctx) {
847851
continue;
848852
}

libbindgen/src/ir/comp.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'a> CanDeriveCopy<'a> for Field {
176176

177177

178178
/// The kind of inheritance a base class is using.
179-
#[derive(Clone, Debug)]
179+
#[derive(Clone, Debug, PartialEq, Eq)]
180180
pub enum BaseKind {
181181
/// Normal inheritance, like:
182182
///
@@ -201,6 +201,13 @@ pub struct Base {
201201
pub kind: BaseKind,
202202
}
203203

204+
impl Base {
205+
/// Whether this base class is inheriting virtually.
206+
pub fn is_virtual(&self) -> bool {
207+
self.kind == BaseKind::Virtual
208+
}
209+
}
210+
204211
/// A compound type.
205212
///
206213
/// Either a struct or union, a compound type is built up from the combination

0 commit comments

Comments
 (0)