Skip to content

Commit b91353c

Browse files
kelldaemilio
authored andcommitted
Mangle items with the same name as Rust primitive types
1 parent 93adc70 commit b91353c

File tree

7 files changed

+222
-25
lines changed

7 files changed

+222
-25
lines changed

src/ir/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,9 @@ If you encounter an error missing from this list, please file an issue or a PR!"
864864
"return" | "Self" | "self" | "sizeof" | "static" |
865865
"struct" | "super" | "trait" | "true" | "type" | "typeof" |
866866
"unsafe" | "unsized" | "use" | "virtual" | "where" |
867-
"while" | "yield" | "bool" | "_" => true,
867+
"while" | "yield" | "str" | "bool" | "f32" | "f64" |
868+
"usize" | "isize" | "u128" | "i128" | "u64" | "i64" |
869+
"u32" | "i32" | "u16" | "i16" | "u8" | "i8" | "_" => true,
868870
_ => false,
869871
}
870872
{
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
#![allow(
4+
dead_code,
5+
non_snake_case,
6+
non_camel_case_types,
7+
non_upper_case_globals
8+
)]
9+
10+
pub type i8_ = i8;
11+
pub type u8_ = u8;
12+
pub type i16_ = i16;
13+
pub type u16_ = u16;
14+
pub type i32_ = i32;
15+
pub type u32_ = u32;
16+
pub type i64_ = i64;
17+
pub type u64_ = u64;
18+
#[repr(C)]
19+
#[derive(Debug, Default, Copy, Clone)]
20+
pub struct Foo {
21+
pub i8_: ::std::os::raw::c_int,
22+
pub u8_: ::std::os::raw::c_int,
23+
pub i16_: ::std::os::raw::c_int,
24+
pub u16_: ::std::os::raw::c_int,
25+
pub i32_: ::std::os::raw::c_int,
26+
pub u32_: ::std::os::raw::c_int,
27+
pub i64_: ::std::os::raw::c_int,
28+
pub u64_: ::std::os::raw::c_int,
29+
pub i128_: ::std::os::raw::c_int,
30+
pub u128_: ::std::os::raw::c_int,
31+
pub isize_: ::std::os::raw::c_int,
32+
pub usize_: ::std::os::raw::c_int,
33+
pub f32_: ::std::os::raw::c_int,
34+
pub f64_: ::std::os::raw::c_int,
35+
}
36+
#[test]
37+
fn bindgen_test_layout_Foo() {
38+
assert_eq!(
39+
::std::mem::size_of::<Foo>(),
40+
56usize,
41+
concat!("Size of: ", stringify!(Foo))
42+
);
43+
assert_eq!(
44+
::std::mem::align_of::<Foo>(),
45+
4usize,
46+
concat!("Alignment of ", stringify!(Foo))
47+
);
48+
assert_eq!(
49+
unsafe { &(*(::std::ptr::null::<Foo>())).i8_ as *const _ as usize },
50+
0usize,
51+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_))
52+
);
53+
assert_eq!(
54+
unsafe { &(*(::std::ptr::null::<Foo>())).u8_ as *const _ as usize },
55+
4usize,
56+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_))
57+
);
58+
assert_eq!(
59+
unsafe { &(*(::std::ptr::null::<Foo>())).i16_ as *const _ as usize },
60+
8usize,
61+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_))
62+
);
63+
assert_eq!(
64+
unsafe { &(*(::std::ptr::null::<Foo>())).u16_ as *const _ as usize },
65+
12usize,
66+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_))
67+
);
68+
assert_eq!(
69+
unsafe { &(*(::std::ptr::null::<Foo>())).i32_ as *const _ as usize },
70+
16usize,
71+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_))
72+
);
73+
assert_eq!(
74+
unsafe { &(*(::std::ptr::null::<Foo>())).u32_ as *const _ as usize },
75+
20usize,
76+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_))
77+
);
78+
assert_eq!(
79+
unsafe { &(*(::std::ptr::null::<Foo>())).i64_ as *const _ as usize },
80+
24usize,
81+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_))
82+
);
83+
assert_eq!(
84+
unsafe { &(*(::std::ptr::null::<Foo>())).u64_ as *const _ as usize },
85+
28usize,
86+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_))
87+
);
88+
assert_eq!(
89+
unsafe { &(*(::std::ptr::null::<Foo>())).i128_ as *const _ as usize },
90+
32usize,
91+
concat!(
92+
"Offset of field: ",
93+
stringify!(Foo),
94+
"::",
95+
stringify!(i128_)
96+
)
97+
);
98+
assert_eq!(
99+
unsafe { &(*(::std::ptr::null::<Foo>())).u128_ as *const _ as usize },
100+
36usize,
101+
concat!(
102+
"Offset of field: ",
103+
stringify!(Foo),
104+
"::",
105+
stringify!(u128_)
106+
)
107+
);
108+
assert_eq!(
109+
unsafe { &(*(::std::ptr::null::<Foo>())).isize_ as *const _ as usize },
110+
40usize,
111+
concat!(
112+
"Offset of field: ",
113+
stringify!(Foo),
114+
"::",
115+
stringify!(isize_)
116+
)
117+
);
118+
assert_eq!(
119+
unsafe { &(*(::std::ptr::null::<Foo>())).usize_ as *const _ as usize },
120+
44usize,
121+
concat!(
122+
"Offset of field: ",
123+
stringify!(Foo),
124+
"::",
125+
stringify!(usize_)
126+
)
127+
);
128+
assert_eq!(
129+
unsafe { &(*(::std::ptr::null::<Foo>())).f32_ as *const _ as usize },
130+
48usize,
131+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_))
132+
);
133+
assert_eq!(
134+
unsafe { &(*(::std::ptr::null::<Foo>())).f64_ as *const _ as usize },
135+
52usize,
136+
concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_))
137+
);
138+
}

tests/expectations/tests/jsval_layout_opaque.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ pub struct jsval_layout__bindgen_ty_2 {
272272
#[repr(C)]
273273
#[derive(Copy, Clone)]
274274
pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 {
275-
pub i32: i32,
276-
pub u32: u32,
275+
pub i32_: i32,
276+
pub u32_: u32,
277277
pub why: JSWhyMagic,
278278
_bindgen_union_align: u32,
279279
}
@@ -298,27 +298,27 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() {
298298
assert_eq!(
299299
unsafe {
300300
&(*(::std::ptr::null::<jsval_layout__bindgen_ty_2__bindgen_ty_1>()))
301-
.i32 as *const _ as usize
301+
.i32_ as *const _ as usize
302302
},
303303
0usize,
304304
concat!(
305305
"Offset of field: ",
306306
stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1),
307307
"::",
308-
stringify!(i32)
308+
stringify!(i32_)
309309
)
310310
);
311311
assert_eq!(
312312
unsafe {
313313
&(*(::std::ptr::null::<jsval_layout__bindgen_ty_2__bindgen_ty_1>()))
314-
.u32 as *const _ as usize
314+
.u32_ as *const _ as usize
315315
},
316316
0usize,
317317
concat!(
318318
"Offset of field: ",
319319
stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1),
320320
"::",
321-
stringify!(u32)
321+
stringify!(u32_)
322322
)
323323
);
324324
assert_eq!(

tests/expectations/tests/jsval_layout_opaque_1_0.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ pub struct jsval_layout__bindgen_ty_2 {
320320
#[repr(C)]
321321
#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)]
322322
pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 {
323-
pub i32: __BindgenUnionField<i32>,
324-
pub u32: __BindgenUnionField<u32>,
323+
pub i32_: __BindgenUnionField<i32>,
324+
pub u32_: __BindgenUnionField<u32>,
325325
pub why: __BindgenUnionField<JSWhyMagic>,
326326
pub bindgen_union_field: u32,
327327
}
@@ -346,27 +346,27 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() {
346346
assert_eq!(
347347
unsafe {
348348
&(*(::std::ptr::null::<jsval_layout__bindgen_ty_2__bindgen_ty_1>()))
349-
.i32 as *const _ as usize
349+
.i32_ as *const _ as usize
350350
},
351351
0usize,
352352
concat!(
353353
"Offset of field: ",
354354
stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1),
355355
"::",
356-
stringify!(i32)
356+
stringify!(i32_)
357357
)
358358
);
359359
assert_eq!(
360360
unsafe {
361361
&(*(::std::ptr::null::<jsval_layout__bindgen_ty_2__bindgen_ty_1>()))
362-
.u32 as *const _ as usize
362+
.u32_ as *const _ as usize
363363
},
364364
0usize,
365365
concat!(
366366
"Offset of field: ",
367367
stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1),
368368
"::",
369-
stringify!(u32)
369+
stringify!(u32_)
370370
)
371371
);
372372
assert_eq!(

tests/expectations/tests/keywords.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,60 @@
88
)]
99

1010
extern "C" {
11-
pub static mut u8: ::std::os::raw::c_int;
11+
#[link_name = "\u{1}u8"]
12+
pub static mut u8_: ::std::os::raw::c_int;
1213
}
1314
extern "C" {
14-
pub static mut u16: ::std::os::raw::c_int;
15+
#[link_name = "\u{1}u16"]
16+
pub static mut u16_: ::std::os::raw::c_int;
1517
}
1618
extern "C" {
17-
pub static mut u32: ::std::os::raw::c_int;
19+
#[link_name = "\u{1}u32"]
20+
pub static mut u32_: ::std::os::raw::c_int;
1821
}
1922
extern "C" {
20-
pub static mut u64: ::std::os::raw::c_int;
23+
#[link_name = "\u{1}u64"]
24+
pub static mut u64_: ::std::os::raw::c_int;
2125
}
2226
extern "C" {
23-
pub static mut i8: ::std::os::raw::c_int;
27+
#[link_name = "\u{1}i8"]
28+
pub static mut i8_: ::std::os::raw::c_int;
2429
}
2530
extern "C" {
26-
pub static mut i16: ::std::os::raw::c_int;
31+
#[link_name = "\u{1}i16"]
32+
pub static mut i16_: ::std::os::raw::c_int;
2733
}
2834
extern "C" {
29-
pub static mut i32: ::std::os::raw::c_int;
35+
#[link_name = "\u{1}i32"]
36+
pub static mut i32_: ::std::os::raw::c_int;
3037
}
3138
extern "C" {
32-
pub static mut i64: ::std::os::raw::c_int;
39+
#[link_name = "\u{1}i64"]
40+
pub static mut i64_: ::std::os::raw::c_int;
3341
}
3442
extern "C" {
35-
pub static mut f32: ::std::os::raw::c_int;
43+
#[link_name = "\u{1}f32"]
44+
pub static mut f32_: ::std::os::raw::c_int;
3645
}
3746
extern "C" {
38-
pub static mut f64: ::std::os::raw::c_int;
47+
#[link_name = "\u{1}f64"]
48+
pub static mut f64_: ::std::os::raw::c_int;
3949
}
4050
extern "C" {
41-
pub static mut usize: ::std::os::raw::c_int;
51+
#[link_name = "\u{1}usize"]
52+
pub static mut usize_: ::std::os::raw::c_int;
4253
}
4354
extern "C" {
44-
pub static mut isize: ::std::os::raw::c_int;
55+
#[link_name = "\u{1}isize"]
56+
pub static mut isize_: ::std::os::raw::c_int;
57+
}
58+
extern "C" {
59+
#[link_name = "\u{1}bool"]
60+
pub static mut bool_: ::std::os::raw::c_int;
61+
}
62+
extern "C" {
63+
#[link_name = "\u{1}str"]
64+
pub static mut str_: ::std::os::raw::c_int;
4565
}
4666
extern "C" {
4767
#[link_name = "\u{1}as"]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
typedef int int8_t;
2+
typedef int uint8_t;
3+
typedef int int16_t;
4+
typedef int uint16_t;
5+
typedef int int32_t;
6+
typedef int uint32_t;
7+
typedef int int64_t;
8+
typedef int uint64_t;
9+
10+
typedef int8_t i8;
11+
typedef uint8_t u8;
12+
typedef int16_t i16;
13+
typedef uint16_t u16;
14+
typedef int32_t i32;
15+
typedef uint32_t u32;
16+
typedef int64_t i64;
17+
typedef uint64_t u64;
18+
19+
struct Foo {
20+
int i8;
21+
int u8;
22+
int i16;
23+
int u16;
24+
int i32;
25+
int u32;
26+
int i64;
27+
int u64;
28+
int i128;
29+
int u128;
30+
int isize;
31+
int usize;
32+
int f32;
33+
int f64;
34+
};

tests/headers/keywords.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ int f32;
1010
int f64;
1111
int usize;
1212
int isize;
13+
int bool;
14+
int str;
15+
1316
int as;
1417
int box;
1518
int crate;

0 commit comments

Comments
 (0)