Skip to content

Commit 379bb16

Browse files
committed
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 rust-lang#768
1 parent c30a805 commit 379bb16

File tree

11 files changed

+439
-75
lines changed

11 files changed

+439
-75
lines changed

src/codegen/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use self::struct_layout::StructLayoutTracker;
99

1010
use super::BindgenOptions;
1111

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

1646-
if ctx.options().rust_features().builtin_clone_impls() ||
1647-
used_template_params.is_some()
1646+
if ctx.options().rust_features().builtin_clone_impls() ||
1647+
used_template_params.is_some()
16481648
{
16491649
// FIXME: This requires extra logic if you have a big array in a
16501650
// templated struct. The reason for this is that the magic:

src/ir/analysis/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ mod derive_partial_eq_or_partial_ord;
5858
pub use self::derive_partial_eq_or_partial_ord::CannotDerivePartialEqOrPartialOrd;
5959
mod has_float;
6060
pub use self::has_float::HasFloat;
61+
mod sizedness;
62+
pub use self::sizedness::{Sizedness, SizednessAnalysis, SizednessResult};
63+
6164
use ir::context::{BindgenContext, ItemId};
6265

6366
use ir::traversal::{EdgeKind, Trace};

0 commit comments

Comments
 (0)