Skip to content

Commit d31ed35

Browse files
committed
ir: Remove an assertion that happens to be invalid.
You can define a struct declared in an outer scope inside another struct, and the compiler won't even complain... C, what a language. Fixes #1281
1 parent fb069e9 commit d31ed35

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

src/ir/comp.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1290,9 +1290,10 @@ impl CompInfo {
12901290
return CXChildVisit_Continue;
12911291
}
12921292

1293+
// Even if this is a definition, we may not be the semantic
1294+
// parent, see #1281.
12931295
let inner = Item::parse(cur, Some(potential_id), ctx)
12941296
.expect("Inner ClassDecl");
1295-
assert_eq!(ctx.resolve_item(inner).parent_id(), potential_id);
12961297

12971298
let inner = inner.expect_type_id(ctx);
12981299

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
4+
5+
#[repr(C)]
6+
#[derive(Debug, Default, Copy, Clone)]
7+
pub struct bar {
8+
pub u: foo,
9+
}
10+
#[repr(C)]
11+
#[derive(Debug, Default, Copy, Clone)]
12+
pub struct foo {
13+
pub foo: ::std::os::raw::c_int,
14+
}
15+
#[test]
16+
fn bindgen_test_layout_foo() {
17+
assert_eq!(
18+
::std::mem::size_of::<foo>(),
19+
4usize,
20+
concat!("Size of: ", stringify!(foo))
21+
);
22+
assert_eq!(
23+
::std::mem::align_of::<foo>(),
24+
4usize,
25+
concat!("Alignment of ", stringify!(foo))
26+
);
27+
assert_eq!(
28+
unsafe { &(*(::std::ptr::null::<foo>())).foo as *const _ as usize },
29+
0usize,
30+
concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo))
31+
);
32+
}
33+
#[test]
34+
fn bindgen_test_layout_bar() {
35+
assert_eq!(
36+
::std::mem::size_of::<bar>(),
37+
4usize,
38+
concat!("Size of: ", stringify!(bar))
39+
);
40+
assert_eq!(
41+
::std::mem::align_of::<bar>(),
42+
4usize,
43+
concat!("Alignment of ", stringify!(bar))
44+
);
45+
assert_eq!(
46+
unsafe { &(*(::std::ptr::null::<bar>())).u as *const _ as usize },
47+
0usize,
48+
concat!("Offset of field: ", stringify!(bar), "::", stringify!(u))
49+
);
50+
}
51+
pub type bar_t = bar;
52+
#[repr(C)]
53+
#[derive(Debug, Default, Copy, Clone)]
54+
pub struct baz {
55+
pub f: foo,
56+
}
57+
#[test]
58+
fn bindgen_test_layout_baz() {
59+
assert_eq!(
60+
::std::mem::size_of::<baz>(),
61+
4usize,
62+
concat!("Size of: ", stringify!(baz))
63+
);
64+
assert_eq!(
65+
::std::mem::align_of::<baz>(),
66+
4usize,
67+
concat!("Alignment of ", stringify!(baz))
68+
);
69+
assert_eq!(
70+
unsafe { &(*(::std::ptr::null::<baz>())).f as *const _ as usize },
71+
0usize,
72+
concat!("Offset of field: ", stringify!(baz), "::", stringify!(f))
73+
);
74+
}

tests/headers/issue-1281.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct foo;
2+
3+
typedef struct bar {
4+
struct foo {
5+
int foo;
6+
} u;
7+
} bar_t;
8+
9+
struct baz {
10+
struct foo f;
11+
};

0 commit comments

Comments
 (0)