Skip to content

Commit 82a74d0

Browse files
author
bors-servo
authored
Auto merge of rust-lang#73 - emilio:complex, r=nox
Be able to represent Complex types with the correct layout. r? @nox
2 parents c21c6f5 + c1639f7 commit 82a74d0

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

src/ir/ty.rs

+7
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,13 @@ impl Type {
631631
.expect("Not able to resolve array element?");
632632
TypeKind::Array(inner, ty.num_elements())
633633
}
634+
// A complex number is always a real and an imaginary part, so
635+
// represent that as a two-item array.
636+
CXType_Complex => {
637+
let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx)
638+
.expect("Not able to resolve array element?");
639+
TypeKind::Array(inner, 2)
640+
}
634641
#[cfg(not(feature="llvm_stable"))]
635642
CXType_Elaborated => {
636643
return Self::from_clang_ty(potential_id, &ty.named(),

tests/expectations/complex.rs

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy)]
9+
pub struct Testdouble {
10+
pub mMember: [f64; 2usize],
11+
}
12+
#[test]
13+
fn bindgen_test_layout_Testdouble() {
14+
assert_eq!(::std::mem::size_of::<Testdouble>() , 16usize);
15+
assert_eq!(::std::mem::align_of::<Testdouble>() , 8usize);
16+
}
17+
impl Clone for Testdouble {
18+
fn clone(&self) -> Self { *self }
19+
}
20+
#[repr(C)]
21+
#[derive(Debug, Copy)]
22+
pub struct TestdoublePtr {
23+
pub mMember: *mut [f64; 2usize],
24+
}
25+
#[test]
26+
fn bindgen_test_layout_TestdoublePtr() {
27+
assert_eq!(::std::mem::size_of::<TestdoublePtr>() , 8usize);
28+
assert_eq!(::std::mem::align_of::<TestdoublePtr>() , 8usize);
29+
}
30+
impl Clone for TestdoublePtr {
31+
fn clone(&self) -> Self { *self }
32+
}
33+
#[repr(C)]
34+
#[derive(Debug, Copy)]
35+
pub struct Testfloat {
36+
pub mMember: [f32; 2usize],
37+
}
38+
#[test]
39+
fn bindgen_test_layout_Testfloat() {
40+
assert_eq!(::std::mem::size_of::<Testfloat>() , 8usize);
41+
assert_eq!(::std::mem::align_of::<Testfloat>() , 4usize);
42+
}
43+
impl Clone for Testfloat {
44+
fn clone(&self) -> Self { *self }
45+
}
46+
#[repr(C)]
47+
#[derive(Debug, Copy)]
48+
pub struct TestfloatPtr {
49+
pub mMember: *mut [f32; 2usize],
50+
}
51+
#[test]
52+
fn bindgen_test_layout_TestfloatPtr() {
53+
assert_eq!(::std::mem::size_of::<TestfloatPtr>() , 8usize);
54+
assert_eq!(::std::mem::align_of::<TestfloatPtr>() , 8usize);
55+
}
56+
impl Clone for TestfloatPtr {
57+
fn clone(&self) -> Self { *self }
58+
}
59+
#[repr(C)]
60+
#[derive(Debug, Copy)]
61+
pub struct Testint {
62+
pub mMember: [::std::os::raw::c_int; 2usize],
63+
}
64+
#[test]
65+
fn bindgen_test_layout_Testint() {
66+
assert_eq!(::std::mem::size_of::<Testint>() , 8usize);
67+
assert_eq!(::std::mem::align_of::<Testint>() , 4usize);
68+
}
69+
impl Clone for Testint {
70+
fn clone(&self) -> Self { *self }
71+
}
72+
#[repr(C)]
73+
#[derive(Debug, Copy)]
74+
pub struct TestintPtr {
75+
pub mMember: *mut [::std::os::raw::c_int; 2usize],
76+
}
77+
#[test]
78+
fn bindgen_test_layout_TestintPtr() {
79+
assert_eq!(::std::mem::size_of::<TestintPtr>() , 8usize);
80+
assert_eq!(::std::mem::align_of::<TestintPtr>() , 8usize);
81+
}
82+
impl Clone for TestintPtr {
83+
fn clone(&self) -> Self { *self }
84+
}

tests/headers/complex.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
#define COMPLEX_TEST(ty_) \
3+
struct Test##ty_ { \
4+
ty_ _Complex mMember; \
5+
\
6+
}; \
7+
struct Test##ty_##Ptr { \
8+
ty_ _Complex* mMember; \
9+
};
10+
11+
COMPLEX_TEST(double)
12+
COMPLEX_TEST(float)
13+
COMPLEX_TEST(int)

0 commit comments

Comments
 (0)