-
Notifications
You must be signed in to change notification settings - Fork 744
codegen: Improve the assertion message of failing layout tests. #487
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -866,8 +866,10 @@ impl CodeGenerator for CompInfo { | |
let item = quote_item!(ctx.ext_cx(), | ||
#[test] | ||
fn $fn_name() { | ||
assert_eq!($size_of_expr, $size); | ||
assert_eq!($align_of_expr, $align); | ||
assert_eq!($size_of_expr, $size, | ||
concat!("Size of template specialization: ", stringify!($ident))); | ||
assert_eq!($align_of_expr, $align, | ||
concat!("Alignment of template specialization: ", stringify!($ident))); | ||
}) | ||
.unwrap(); | ||
result.push(item); | ||
|
@@ -1339,12 +1341,12 @@ impl CodeGenerator for CompInfo { | |
if let Some(layout) = layout { | ||
let fn_name = format!("bindgen_test_layout_{}", canonical_name); | ||
let fn_name = ctx.rust_ident_raw(&fn_name); | ||
let ident = ctx.rust_ident_raw(&canonical_name); | ||
let type_name = ctx.rust_ident_raw(&canonical_name); | ||
let prefix = ctx.trait_prefix(); | ||
let size_of_expr = quote_expr!(ctx.ext_cx(), | ||
::$prefix::mem::size_of::<$ident>()); | ||
::$prefix::mem::size_of::<$type_name>()); | ||
let align_of_expr = quote_expr!(ctx.ext_cx(), | ||
::$prefix::mem::align_of::<$ident>()); | ||
::$prefix::mem::align_of::<$type_name>()); | ||
let size = layout.size; | ||
let align = layout.align; | ||
|
||
|
@@ -1353,7 +1355,9 @@ impl CodeGenerator for CompInfo { | |
None | ||
} else { | ||
quote_item!(ctx.ext_cx(), | ||
assert_eq!($align_of_expr, $align); | ||
assert_eq!($align_of_expr, | ||
$align, | ||
concat!("Alignment of ", stringify!($type_name))); | ||
) | ||
}; | ||
|
||
|
@@ -1370,8 +1374,6 @@ impl CodeGenerator for CompInfo { | |
let check_field_offset = if should_skip_field_offset_checks { | ||
None | ||
} else { | ||
let type_name = ctx.rust_ident(&canonical_name); | ||
|
||
let asserts = self.fields() | ||
.iter() | ||
.filter(|field| field.bitfield().is_none()) | ||
|
@@ -1382,7 +1384,9 @@ impl CodeGenerator for CompInfo { | |
let field_name = ctx.rust_ident(name); | ||
|
||
quote_item!(ctx.ext_cx(), | ||
assert_eq!(unsafe { &(*(0 as *const $type_name)).$field_name as *const _ as usize }, $field_offset); | ||
assert_eq!(unsafe { &(*(0 as *const $type_name)).$field_name as *const _ as usize }, | ||
$field_offset, | ||
concat!("Alignment of field: ", stringify!($type_name), "::", stringify!($field_name))); | ||
) | ||
}) | ||
}) | ||
|
@@ -1394,7 +1398,9 @@ impl CodeGenerator for CompInfo { | |
let item = quote_item!(ctx.ext_cx(), | ||
#[test] | ||
fn $fn_name() { | ||
assert_eq!($size_of_expr, $size); | ||
assert_eq!($size_of_expr, | ||
$size, | ||
concat!("Size of: ", stringify!($type_name))); | ||
|
||
$check_struct_align | ||
$check_field_offset | ||
|
@@ -2137,7 +2143,7 @@ impl ToRustTy for Type { | |
.map(|arg| arg.to_rust_ty(ctx)) | ||
.collect::<Vec<_>>(); | ||
|
||
path.segments.last_mut().unwrap().parameters = if | ||
path.segments.last_mut().unwrap().parameters = if | ||
template_args.is_empty() { | ||
None | ||
} else { | ||
|
@@ -2458,12 +2464,12 @@ mod utils { | |
use aster; | ||
use ir::context::{BindgenContext, ItemId}; | ||
use ir::item::{Item, ItemCanonicalPath}; | ||
use ir::function::FunctionSig; | ||
use ir::ty::TypeKind; | ||
use std::mem; | ||
use syntax::ast; | ||
use syntax::ptr::P; | ||
|
||
|
||
pub fn prepend_objc_header(ctx: &BindgenContext, | ||
result: &mut Vec<P<ast::Item>>) { | ||
let use_objc = if ctx.options().objc_extern_crate { | ||
|
@@ -2745,7 +2751,7 @@ mod utils { | |
} | ||
|
||
pub fn fnsig_return_ty(ctx: &BindgenContext, | ||
sig: &super::FunctionSig) | ||
sig: &FunctionSig) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are going to support older rustc, we should add the oldest supported version to our travis ci matrix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only temporary until Gecko updates is rustc version anyway, should be <1week |
||
-> ast::FunctionRetTy { | ||
let return_item = ctx.resolve_item(sig.return_type()); | ||
if let TypeKind::Void = *return_item.kind().expect_type().kind() { | ||
|
@@ -2756,7 +2762,7 @@ mod utils { | |
} | ||
|
||
pub fn fnsig_arguments(ctx: &BindgenContext, | ||
sig: &super::FunctionSig) | ||
sig: &FunctionSig) | ||
-> Vec<ast::Arg> { | ||
use super::ToPtr; | ||
let mut unnamed_arguments = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch is good to me, something else observed.
Do we need check the field offset for the template specialization?
It seems be different to VTable case, should have potential layout issue. Anyway, I haven't user cases in wild