Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
591 changes: 591 additions & 0 deletions bindgen-tests/tests/expectations/tests/bitfield-unparsed-method.rs

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions bindgen-tests/tests/headers/bitfield-unparsed-method.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// bindgen-flags: --allowlist-type StructWithBitfieldAndMethod -- -std=c++20

struct Base {
template<typename T> void t_func(T t);
};

struct StructWithBitfieldAndMethod : Base {
int field : 1;
template<typename T> void t_method(T t);
void regular_method();
};
11 changes: 11 additions & 0 deletions bindgen-tests/tests/headers/non-recursive-array-layout.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// bindgen-flags: --allowlist-type OuterArrayStruct --no-recursive-allowlist --raw-line "pub struct UnparsedArrayElem(pub u32);"

template <typename T>
struct UnparsedArrayElem {
T val;
template <typename U> void unparsed_method(U u);
};

struct OuterArrayStruct {
UnparsedArrayElem<int> flex_array[0];
};
11 changes: 11 additions & 0 deletions bindgen-tests/tests/headers/non-recursive-field-layout.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// bindgen-flags: --allowlist-type OuterStruct --no-recursive-allowlist --raw-line "pub struct UnparsedTemplate(pub u32);"

template <typename T>
struct UnparsedTemplate {
T val;
template <typename U> void unparsed_method(U u);
};

struct OuterStruct {
UnparsedTemplate<int> field;
};
15 changes: 10 additions & 5 deletions bindgen/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Field {
match *self {
Field::Bitfields(BitfieldUnit { layout, .. }) => Some(layout),
Field::DataMember(ref data) => {
ctx.resolve_type(data.ty).layout(ctx)
ctx.safe_resolve_type(data.ty)?.layout(ctx)
}
}
}
Expand Down Expand Up @@ -765,7 +765,11 @@ impl CompFields {
name: &str,
) -> bool {
methods.iter().any(|method| {
let method_name = ctx.resolve_func(method.signature()).name();
let Some(func) = ctx.resolve_func_fallible(method.signature())
else {
return false;
};
let method_name = func.name();
method_name == name || ctx.rust_mangle(method_name) == name
})
}
Expand Down Expand Up @@ -1214,9 +1218,10 @@ impl CompInfo {
}
CompFields::Before(ref raw_fields) => {
for field in raw_fields {
let field_ty = ctx.resolve_type(field.0.ty);
if let Some(layout) = field_ty.layout(ctx) {
callback(layout);
if let Some(field_ty) = ctx.safe_resolve_type(field.0.ty) {
if let Some(layout) = field_ty.layout(ctx) {
callback(layout);
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
///
/// Panics if there is no item for the given `FunctionId` or if the resolved
/// item is not a `Function`.
#[allow(dead_code)]
pub(crate) fn resolve_func(&self, func_id: FunctionId) -> &Function {
self.resolve_item(func_id).kind().expect_function()
}
Expand All @@ -1476,6 +1477,18 @@ If you encounter an error missing from this list, please file an issue or a PR!"
.map(|t| t.kind().expect_type())
}

/// Resolve the given `ItemId` as a function, or `None` if there is no item
/// with the given ID.
///
/// Panics if the ID resolves to an item that is not a function.
pub(crate) fn resolve_func_fallible(
&self,
func_id: FunctionId,
) -> Option<&Function> {
self.resolve_item_fallible(func_id)
.map(|t| t.kind().expect_function())
}

/// Resolve the given `ItemId` into an `Item`, or `None` if no such item
/// exists.
pub(crate) fn resolve_item_fallible<Id: Into<ItemId>>(
Expand Down
4 changes: 2 additions & 2 deletions bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl Type {
TypeKind::Comp(ref ci) => ci.layout(ctx),
TypeKind::Array(inner, 0) => Some(Layout::new(
0,
ctx.resolve_type(inner).layout(ctx)?.align,
ctx.safe_resolve_type(inner)?.layout(ctx)?.align,
)),
// FIXME(emilio): This is a hack for anonymous union templates.
// Use the actual pointer size!
Expand All @@ -232,7 +232,7 @@ impl Type {
ctx.target_pointer_size(),
)),
TypeKind::ResolvedTypeRef(inner) => {
ctx.resolve_type(inner).layout(ctx)
ctx.safe_resolve_type(inner)?.layout(ctx)
}
_ => None,
}
Expand Down
Loading