diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-01-18 23:37:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-18 23:37:55 +0100 |
commit | 7a5ae200e9d7d38a72cb0be11c9e9a6cfceeb839 (patch) | |
tree | f8c6cfef724ca88949dff56da2f31b05cb65f122 | |
parent | 42bfc232d3de3600cfa070cc6dab13a45870dc90 (diff) | |
parent | 5c92043f2a1b42d52fc2468c2baf0c9cc597c1f8 (diff) |
Merge pull request #1495 from tromey/packed-only-vtable
Fix layout with packed class that only has a vtable
-rw-r--r-- | src/ir/comp.rs | 4 | ||||
-rw-r--r-- | tests/expectations/tests/packed-vtable.rs | 39 | ||||
-rw-r--r-- | tests/headers/packed-vtable.h | 10 |
3 files changed, 53 insertions, 0 deletions
diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 12a8fa32..85054e5a 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1517,6 +1517,10 @@ impl CompInfo { }) { info!("Found a struct that was defined within `#pragma packed(...)`"); return true; + } else if self.has_own_virtual_method { + if parent_layout.align == 1 { + return true; + } } } diff --git a/tests/expectations/tests/packed-vtable.rs b/tests/expectations/tests/packed-vtable.rs new file mode 100644 index 00000000..4bb206c6 --- /dev/null +++ b/tests/expectations/tests/packed-vtable.rs @@ -0,0 +1,39 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(feature = "nightly")] + +#[repr(C)] +pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void); +#[repr(C, packed)] +#[derive(Debug)] +pub struct PackedVtable { + pub vtable_: *const PackedVtable__bindgen_vtable, +} +#[test] +fn bindgen_test_layout_PackedVtable() { + assert_eq!( + ::std::mem::size_of::<PackedVtable>(), + 8usize, + concat!("Size of: ", stringify!(PackedVtable)) + ); + assert_eq!( + ::std::mem::align_of::<PackedVtable>(), + 1usize, + concat!("Alignment of ", stringify!(PackedVtable)) + ); +} +impl Default for PackedVtable { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +extern "C" { + #[link_name = "\u{1}_ZN12PackedVtableD1Ev"] + pub fn PackedVtable_PackedVtable_destructor(this: *mut PackedVtable); +} diff --git a/tests/headers/packed-vtable.h b/tests/headers/packed-vtable.h new file mode 100644 index 00000000..d2413d45 --- /dev/null +++ b/tests/headers/packed-vtable.h @@ -0,0 +1,10 @@ +// bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' --rust-target 1.33 -- -x c++ -std=c++11 + +#pragma pack(1) + +// This should be packed. +struct PackedVtable { + virtual ~PackedVtable(); +}; + +#pragma pack() |