Skip to content

Commit

Permalink
Auto merge of #1102 - fitzgen:sizedness, r=pepyakin
Browse files Browse the repository at this point in the history
Compute sizedness with a fixed-point analysis

This fixes a couple bugs where we weren't properly adding an `_address` byte. It also helps pave the way for computing implicit fields (such as padding, `_address`, vtable pointers, etc) in its own pass, before codegen.

Fixes #768

r? @pepyakin
  • Loading branch information
bors-servo authored Oct 25, 2017
2 parents 6a48ca9 + d018f42 commit 88a1e24
Show file tree
Hide file tree
Showing 15 changed files with 625 additions and 75 deletions.
10 changes: 5 additions & 5 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use self::struct_layout::StructLayoutTracker;

use super::BindgenOptions;

use ir::analysis::HasVtable;
use ir::analysis::{HasVtable, Sizedness};
use ir::annotations::FieldAccessorKind;
use ir::comment;
use ir::comp::{Base, Bitfield, BitfieldUnit, CompInfo, CompKind, Field,
Expand Down Expand Up @@ -1534,7 +1534,7 @@ impl CodeGenerator for CompInfo {
warn!("Opaque type without layout! Expect dragons!");
}
}
} else if !is_union && !self.is_unsized(ctx, item.id().expect_type_id(ctx)) {
} else if !is_union && !item.is_zero_sized(ctx) {
if let Some(padding_field) =
layout.and_then(|layout| struct_layout.pad_struct(layout))
{
Expand Down Expand Up @@ -1565,7 +1565,7 @@ impl CodeGenerator for CompInfo {
//
// NOTE: This check is conveniently here to avoid the dummy fields we
// may add for unused template parameters.
if self.is_unsized(ctx, item.id().expect_type_id(ctx)) {
if item.is_zero_sized(ctx) {
let has_address = if is_opaque {
// Generate the address field if it's an opaque type and
// couldn't determine the layout of the blob.
Expand Down Expand Up @@ -1643,8 +1643,8 @@ impl CodeGenerator for CompInfo {
{
derives.push("Copy");

if ctx.options().rust_features().builtin_clone_impls() ||
used_template_params.is_some()
if ctx.options().rust_features().builtin_clone_impls() ||
used_template_params.is_some()
{
// FIXME: This requires extra logic if you have a big array in a
// templated struct. The reason for this is that the magic:
Expand Down
3 changes: 3 additions & 0 deletions src/ir/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ mod derive_partial_eq_or_partial_ord;
pub use self::derive_partial_eq_or_partial_ord::CannotDerivePartialEqOrPartialOrd;
mod has_float;
pub use self::has_float::HasFloat;
mod sizedness;
pub use self::sizedness::{Sizedness, SizednessAnalysis, SizednessResult};

use ir::context::{BindgenContext, ItemId};

use ir::traversal::{EdgeKind, Trace};
Expand Down
Loading

0 comments on commit 88a1e24

Please sign in to comment.