summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clang.rs8
-rw-r--r--src/ir/ty.rs8
-rw-r--r--tests/expectations/vector.rs19
-rw-r--r--tests/headers/vector.hpp3
4 files changed, 33 insertions, 5 deletions
diff --git a/src/clang.rs b/src/clang.rs
index ec6dbbe5..f98644ce 100644
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -536,16 +536,16 @@ impl Type {
}
}
- // array
+ // array, vector or complex.
pub fn elem_type(&self) -> Type {
unsafe {
- Type { x: clang_getArrayElementType(self.x) }
+ Type { x: clang_getElementType(self.x) }
}
}
- pub fn array_size(&self) -> usize {
+ pub fn num_elements(&self) -> usize {
unsafe {
- clang_getArraySize(self.x) as usize
+ clang_getNumElements(self.x) as usize
}
}
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index 74452243..8227a786 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -538,10 +538,16 @@ impl Type {
.expect("Not a complex type?");
TypeKind::Comp(complex)
}
+ // FIXME: We stub vectors as arrays since in 99% of the cases the
+ // layout is going to be correct, and there's no way we can generate
+ // vector types properly in Rust for now.
+ //
+ // That being said, that should be fixed eventually.
+ CXType_Vector |
CXType_ConstantArray => {
let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx)
.expect("Not able to resolve array element?");
- TypeKind::Array(inner, ty.array_size())
+ TypeKind::Array(inner, ty.num_elements())
}
#[cfg(not(feature="llvm_stable"))]
CXType_Elaborated => {
diff --git a/tests/expectations/vector.rs b/tests/expectations/vector.rs
new file mode 100644
index 00000000..b8ca5735
--- /dev/null
+++ b/tests/expectations/vector.rs
@@ -0,0 +1,19 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy)]
+pub struct foo {
+ pub mMember: [::std::os::raw::c_longlong; 1usize],
+}
+#[test]
+fn bindgen_test_layout_foo() {
+ assert_eq!(::std::mem::size_of::<foo>() , 8usize);
+ assert_eq!(::std::mem::align_of::<foo>() , 8usize);
+}
+impl Clone for foo {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/headers/vector.hpp b/tests/headers/vector.hpp
new file mode 100644
index 00000000..4707f77f
--- /dev/null
+++ b/tests/headers/vector.hpp
@@ -0,0 +1,3 @@
+struct foo {
+ __attribute__((__vector_size__(1 * sizeof(long long)))) long long mMember;
+};