Skip to content

Commit 104bd52

Browse files
author
bors-servo
authored
Auto merge of #808 - fitzgen:issue-807-opaque-types-methods-getting-generated, r=emilio
Fix tracing of opaque types This makes tracing opaque types' edges match what we codegen for opaque types. Although we still generate constructors, methods, etc for opaque types (just not fields and base members) we were not tracing them. Fixes #807 This miiight be related to https://bugzilla.mozilla.org/show_bug.cgi?id=1366050 too. r? @emilio
2 parents a00db04 + 8b3dfaa commit 104bd52

File tree

4 files changed

+167
-13
lines changed

4 files changed

+167
-13
lines changed

src/ir/comp.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,19 +1582,6 @@ impl Trace for CompInfo {
15821582
tracer.visit_kind(ty, EdgeKind::InnerType);
15831583
}
15841584

1585-
// We unconditionally trace `CompInfo`'s template parameters and inner
1586-
// types for the the usage analysis. However, we don't want to continue
1587-
// tracing anything else, if this type is marked opaque.
1588-
if item.is_opaque(context, &()) {
1589-
return;
1590-
}
1591-
1592-
for base in self.base_members() {
1593-
tracer.visit_kind(base.ty, EdgeKind::BaseMember);
1594-
}
1595-
1596-
self.fields.trace(context, tracer, &());
1597-
15981585
for &var in self.inner_vars() {
15991586
tracer.visit_kind(var, EdgeKind::InnerVar);
16001587
}
@@ -1606,5 +1593,17 @@ impl Trace for CompInfo {
16061593
for &ctor in self.constructors() {
16071594
tracer.visit_kind(ctor, EdgeKind::Constructor);
16081595
}
1596+
1597+
// Base members and fields are not generated for opaque types (but all
1598+
// of the above things are) so stop here.
1599+
if item.is_opaque(context, &()) {
1600+
return;
1601+
}
1602+
1603+
for base in self.base_members() {
1604+
tracer.visit_kind(base.ty, EdgeKind::BaseMember);
1605+
}
1606+
1607+
self.fields.trace(context, tracer, &());
16091608
}
16101609
}

tests/expectations/tests/issue-801-opaque-sloppiness.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
55

66

7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct A {
10+
_unused: [u8; 0],
11+
}
712
#[repr(C)]
813
#[derive(Debug, Default, Copy)]
914
pub struct B {
@@ -19,6 +24,10 @@ fn bindgen_test_layout_B() {
1924
impl Clone for B {
2025
fn clone(&self) -> Self { *self }
2126
}
27+
extern "C" {
28+
#[link_name = "_ZN1B1aE"]
29+
pub static mut B_a: A;
30+
}
2231
#[repr(C)]
2332
#[derive(Debug, Default, Copy)]
2433
pub struct C {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Default, Copy)]
9+
pub struct Pupper {
10+
pub _address: u8,
11+
}
12+
#[test]
13+
fn bindgen_test_layout_Pupper() {
14+
assert_eq!(::std::mem::size_of::<Pupper>() , 1usize , concat ! (
15+
"Size of: " , stringify ! ( Pupper ) ));
16+
assert_eq! (::std::mem::align_of::<Pupper>() , 1usize , concat ! (
17+
"Alignment of " , stringify ! ( Pupper ) ));
18+
}
19+
impl Clone for Pupper {
20+
fn clone(&self) -> Self { *self }
21+
}
22+
#[repr(C)]
23+
#[derive(Debug, Default, Copy)]
24+
pub struct Doggo {
25+
pub _address: u8,
26+
}
27+
#[test]
28+
fn bindgen_test_layout_Doggo() {
29+
assert_eq!(::std::mem::size_of::<Doggo>() , 1usize , concat ! (
30+
"Size of: " , stringify ! ( Doggo ) ));
31+
assert_eq! (::std::mem::align_of::<Doggo>() , 1usize , concat ! (
32+
"Alignment of " , stringify ! ( Doggo ) ));
33+
}
34+
impl Clone for Doggo {
35+
fn clone(&self) -> Self { *self }
36+
}
37+
#[repr(C)]
38+
#[derive(Debug, Default, Copy)]
39+
pub struct SuchWow {
40+
pub _address: u8,
41+
}
42+
#[test]
43+
fn bindgen_test_layout_SuchWow() {
44+
assert_eq!(::std::mem::size_of::<SuchWow>() , 1usize , concat ! (
45+
"Size of: " , stringify ! ( SuchWow ) ));
46+
assert_eq! (::std::mem::align_of::<SuchWow>() , 1usize , concat ! (
47+
"Alignment of " , stringify ! ( SuchWow ) ));
48+
}
49+
impl Clone for SuchWow {
50+
fn clone(&self) -> Self { *self }
51+
}
52+
#[repr(C)]
53+
#[derive(Debug, Default, Copy)]
54+
pub struct Opaque {
55+
pub _bindgen_opaque_blob: u8,
56+
}
57+
#[test]
58+
fn bindgen_test_layout_Opaque() {
59+
assert_eq!(::std::mem::size_of::<Opaque>() , 1usize , concat ! (
60+
"Size of: " , stringify ! ( Opaque ) ));
61+
assert_eq! (::std::mem::align_of::<Opaque>() , 1usize , concat ! (
62+
"Alignment of " , stringify ! ( Opaque ) ));
63+
}
64+
extern "C" {
65+
#[link_name = "_ZN6Opaque17eleven_out_of_tenEv"]
66+
pub fn Opaque_eleven_out_of_ten(this: *mut Opaque) -> SuchWow;
67+
}
68+
extern "C" {
69+
#[link_name = "_ZN6OpaqueC1E6Pupper"]
70+
pub fn Opaque_Opaque(this: *mut Opaque, pup: Pupper);
71+
}
72+
impl Clone for Opaque {
73+
fn clone(&self) -> Self { *self }
74+
}
75+
impl Opaque {
76+
#[inline]
77+
pub unsafe fn eleven_out_of_ten(&mut self) -> SuchWow {
78+
Opaque_eleven_out_of_ten(self)
79+
}
80+
#[inline]
81+
pub unsafe fn new(pup: Pupper) -> Self {
82+
let mut __bindgen_tmp = ::std::mem::uninitialized();
83+
Opaque_Opaque(&mut __bindgen_tmp, pup);
84+
__bindgen_tmp
85+
}
86+
}
87+
extern "C" {
88+
#[link_name = "_ZN6Opaque11MAJESTIC_AFE"]
89+
pub static mut Opaque_MAJESTIC_AF: Doggo;
90+
}
91+
#[repr(C)]
92+
#[derive(Debug, Default, Copy)]
93+
pub struct Whitelisted {
94+
pub some_member: Opaque,
95+
}
96+
#[test]
97+
fn bindgen_test_layout_Whitelisted() {
98+
assert_eq!(::std::mem::size_of::<Whitelisted>() , 1usize , concat ! (
99+
"Size of: " , stringify ! ( Whitelisted ) ));
100+
assert_eq! (::std::mem::align_of::<Whitelisted>() , 1usize , concat ! (
101+
"Alignment of " , stringify ! ( Whitelisted ) ));
102+
assert_eq! (unsafe {
103+
& ( * ( 0 as * const Whitelisted ) ) . some_member as * const
104+
_ as usize } , 0usize , concat ! (
105+
"Alignment of field: " , stringify ! ( Whitelisted ) , "::" ,
106+
stringify ! ( some_member ) ));
107+
}
108+
impl Clone for Whitelisted {
109+
fn clone(&self) -> Self { *self }
110+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// bindgen-flags: --whitelist-type Whitelisted --opaque-type Opaque -- -std=c++11
2+
3+
// These types are not explicitly whitelisted, but are reachable through the
4+
// opaque type.
5+
class Pupper {};
6+
class Doggo {};
7+
class SuchWow {};
8+
9+
// These types are not whitelisted, and would be reachable through `Opaque` if
10+
// it were not marked opaque, but since it is, there should be no bindings
11+
// generated for them.
12+
class NoBindingsShouldBeGeneratedForMe1 {};
13+
class NoBindingsShouldBeGeneratedForMe2 {};
14+
15+
// Exercise the different kinds of outgoing edges from an opaque type.
16+
class Opaque
17+
// Base member edge.
18+
: public NoBindingsShouldBeGeneratedForMe1 {
19+
20+
protected:
21+
// Field edge.
22+
NoBindingsShouldBeGeneratedForMe2 field;
23+
24+
// Constructor edge.
25+
Opaque(Pupper pup);
26+
27+
// Inner static variable edge.
28+
static Doggo MAJESTIC_AF;
29+
30+
// Method edge.
31+
SuchWow eleven_out_of_ten();
32+
};
33+
34+
class Whitelisted {
35+
Opaque some_member;
36+
};

0 commit comments

Comments
 (0)