diff options
| author | Cameron Hart <cameron.hart@gmail.com> | 2018-02-04 22:10:28 +1100 |
|---|---|---|
| committer | Cameron Hart <cameron.hart@gmail.com> | 2018-04-11 22:13:13 +1000 |
| commit | 15d1c4d2139611fcb87a2c802bd015b5f4f0aed8 (patch) | |
| tree | 5822428a8e6a8ef94f13ea80f22d8ec01545f33b /src/librustc/session | |
| parent | ca26ef321c44358404ef788d315c4557eb015fb2 (diff) | |
| download | rust-15d1c4d2139611fcb87a2c802bd015b5f4f0aed8.tar.gz rust-15d1c4d2139611fcb87a2c802bd015b5f4f0aed8.zip | |
Implementation of `#[repr(packed(n))]` RFC 1399.
Diffstat (limited to 'src/librustc/session')
| -rw-r--r-- | src/librustc/session/code_stats.rs | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/librustc/session/code_stats.rs b/src/librustc/session/code_stats.rs index 64f405e0f24..df4060e71e5 100644 --- a/src/librustc/session/code_stats.rs +++ b/src/librustc/session/code_stats.rs @@ -62,6 +62,7 @@ pub struct TypeSizeInfo { pub type_description: String, pub align: u64, pub overall_size: u64, + pub packed: bool, pub opt_discr_size: Option<u64>, pub variants: Vec<VariantInfo>, } @@ -79,6 +80,7 @@ impl CodeStats { type_desc: S, align: Align, overall_size: Size, + packed: bool, opt_discr_size: Option<Size>, variants: Vec<VariantInfo>) { let info = TypeSizeInfo { @@ -86,6 +88,7 @@ impl CodeStats { type_description: type_desc.to_string(), align: align.abi(), overall_size: overall_size.bytes(), + packed: packed, opt_discr_size: opt_discr_size.map(|s| s.bytes()), variants, }; @@ -153,24 +156,26 @@ impl CodeStats { for field in fields.iter() { let FieldInfo { ref name, offset, size, align } = *field; - // Include field alignment in output only if it caused padding injection - if min_offset != offset { - if offset > min_offset { - let pad = offset - min_offset; - println!("print-type-size {}padding: {} bytes", - indent, pad); - println!("print-type-size {}field `.{}`: {} bytes, \ - alignment: {} bytes", - indent, name, size, align); - } else { - println!("print-type-size {}field `.{}`: {} bytes, \ - offset: {} bytes, \ - alignment: {} bytes", - indent, name, size, offset, align); - } - } else { + if offset > min_offset { + let pad = offset - min_offset; + println!("print-type-size {}padding: {} bytes", + indent, pad); + } + + if offset < min_offset { + // if this happens something is very wrong + println!("print-type-size {}field `.{}`: {} bytes, \ + offset: {} bytes, \ + alignment: {} bytes", + indent, name, size, offset, align); + } else if info.packed || offset == min_offset { println!("print-type-size {}field `.{}`: {} bytes", indent, name, size); + } else { + // Include field alignment in output only if it caused padding injection + println!("print-type-size {}field `.{}`: {} bytes, \ + alignment: {} bytes", + indent, name, size, align); } min_offset = offset + size; |
