Skip to content

Commit 038381c

Browse files
author
bors-servo
authored
Auto merge of #842 - emilio:derive-debug-opaque-inst, r=Manishearth
analysis: Account for template instantiations of opaque types in the derive debug analysis. We have a special-case for them in codegen to generate a blob, that can derive debug. This is a regression from #824, and hit stylo.
2 parents ed4facf + bff026c commit 038381c

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

src/ir/analysis/derive_debug.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::{ConstrainResult, MonotoneFramework};
44
use std::collections::HashSet;
55
use std::collections::HashMap;
66
use ir::context::{BindgenContext, ItemId};
7+
use ir::item::IsOpaque;
78
use ir::traversal::EdgeKind;
89
use ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
910
use ir::ty::TypeKind;
@@ -260,19 +261,23 @@ impl<'ctx, 'gen> MonotoneFramework for CannotDeriveDebug<'ctx, 'gen> {
260261
return self.insert(id);
261262
}
262263

263-
let ty_cannot_derive = template.template_definition()
264+
let template_definition = template.template_definition()
264265
.into_resolver()
265266
.through_type_refs()
266267
.through_type_aliases()
267-
.resolve(self.ctx)
268+
.resolve(self.ctx);
269+
270+
let ty_cannot_derive = template_definition
268271
.as_type()
269272
.expect("Instantiations of a non-type?")
270273
.as_comp()
271274
.and_then(|c| {
272-
// For non-type template parameters, we generate an opaque
273-
// blob, and in this case the instantiation has a better
274-
// idea of the layout than the definition does.
275-
if c.has_non_type_template_params() {
275+
// For non-type template parameters, or opaque template
276+
// definitions, we generate an opaque blob, and in this
277+
// case the instantiation has a better idea of the
278+
// layout than the definition does.
279+
if template_definition.is_opaque(self.ctx, &()) ||
280+
c.has_non_type_template_params() {
276281
let opaque = ty.layout(self.ctx)
277282
.or_else(|| {
278283
self.ctx
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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(Copy, Clone)]
9+
pub struct OpaqueTemplate {
10+
}
11+
impl Default for OpaqueTemplate {
12+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
13+
}
14+
#[repr(C)]
15+
#[derive(Debug, Default, Copy)]
16+
pub struct ContainsOpaqueTemplate {
17+
pub mBlah: [u32; 11usize],
18+
pub mBaz: ::std::os::raw::c_int,
19+
}
20+
#[test]
21+
fn bindgen_test_layout_ContainsOpaqueTemplate() {
22+
assert_eq!(::std::mem::size_of::<ContainsOpaqueTemplate>() , 48usize ,
23+
concat ! ( "Size of: " , stringify ! ( ContainsOpaqueTemplate )
24+
));
25+
assert_eq! (::std::mem::align_of::<ContainsOpaqueTemplate>() , 4usize ,
26+
concat ! (
27+
"Alignment of " , stringify ! ( ContainsOpaqueTemplate ) ));
28+
assert_eq! (unsafe {
29+
& ( * ( 0 as * const ContainsOpaqueTemplate ) ) . mBlah as *
30+
const _ as usize } , 0usize , concat ! (
31+
"Alignment of field: " , stringify ! ( ContainsOpaqueTemplate
32+
) , "::" , stringify ! ( mBlah ) ));
33+
assert_eq! (unsafe {
34+
& ( * ( 0 as * const ContainsOpaqueTemplate ) ) . mBaz as *
35+
const _ as usize } , 44usize , concat ! (
36+
"Alignment of field: " , stringify ! ( ContainsOpaqueTemplate
37+
) , "::" , stringify ! ( mBaz ) ));
38+
}
39+
impl Clone for ContainsOpaqueTemplate {
40+
fn clone(&self) -> Self { *self }
41+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// bindgen-flags: --opaque-type 'OpaqueTemplate'
2+
3+
template<typename T>
4+
class OpaqueTemplate {
5+
T mData;
6+
bool mCannotDebug[40];
7+
};
8+
9+
class ContainsOpaqueTemplate {
10+
OpaqueTemplate<int> mBlah;
11+
int mBaz;
12+
};

0 commit comments

Comments
 (0)