summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clang.rs47
-rw-r--r--tests/expectations/tests/bug-1529681.rs27
-rw-r--r--tests/headers/bug-1529681.hpp8
3 files changed, 66 insertions, 16 deletions
diff --git a/src/clang.rs b/src/clang.rs
index 10bf054a..40ba60e8 100644
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -931,18 +931,37 @@ impl Type {
unsafe { clang_isConstQualifiedType(self.x) != 0 }
}
+ #[inline]
+ fn is_non_deductible_auto_type(&self) -> bool {
+ self.kind() == CXType_Auto && self.canonical_type() == *self
+ }
+
+ #[inline]
+ fn clang_size_of(&self) -> c_longlong {
+ if self.is_non_deductible_auto_type() {
+ return -6; // Work-around https://bugs.llvm.org/show_bug.cgi?id=40813
+ }
+ unsafe { clang_Type_getSizeOf(self.x) }
+ }
+
+ #[inline]
+ fn clang_align_of(&self) -> c_longlong {
+ if self.is_non_deductible_auto_type() {
+ return -6; // Work-around https://bugs.llvm.org/show_bug.cgi?id=40813
+ }
+ unsafe { clang_Type_getAlignOf(self.x) }
+ }
+
/// What is the size of this type? Paper over invalid types by returning `0`
/// for them.
pub fn size(&self) -> usize {
- unsafe {
- let val = clang_Type_getSizeOf(self.x);
- if val < 0 { 0 } else { val as usize }
- }
+ let val = self.clang_size_of();
+ if val < 0 { 0 } else { val as usize }
}
/// What is the size of this type?
pub fn fallible_size(&self) -> Result<usize, LayoutError> {
- let val = unsafe { clang_Type_getSizeOf(self.x) };
+ let val = self.clang_size_of();
if val < 0 {
Err(LayoutError::from(val as i32))
} else {
@@ -953,21 +972,17 @@ impl Type {
/// What is the alignment of this type? Paper over invalid types by
/// returning `0`.
pub fn align(&self) -> usize {
- unsafe {
- let val = clang_Type_getAlignOf(self.x);
- if val < 0 { 0 } else { val as usize }
- }
+ let val = self.clang_align_of();
+ if val < 0 { 0 } else { val as usize }
}
/// What is the alignment of this type?
pub fn fallible_align(&self) -> Result<usize, LayoutError> {
- unsafe {
- let val = clang_Type_getAlignOf(self.x);
- if val < 0 {
- Err(LayoutError::from(val as i32))
- } else {
- Ok(val as usize)
- }
+ let val = self.clang_align_of();
+ if val < 0 {
+ Err(LayoutError::from(val as i32))
+ } else {
+ Ok(val as usize)
}
}
diff --git a/tests/expectations/tests/bug-1529681.rs b/tests/expectations/tests/bug-1529681.rs
new file mode 100644
index 00000000..81a32093
--- /dev/null
+++ b/tests/expectations/tests/bug-1529681.rs
@@ -0,0 +1,27 @@
+/* automatically generated by rust-bindgen */
+
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct BrowsingContext {
+ pub _address: u8,
+}
+#[test]
+fn bindgen_test_layout_BrowsingContext() {
+ assert_eq!(
+ ::std::mem::size_of::<BrowsingContext>(),
+ 1usize,
+ concat!("Size of: ", stringify!(BrowsingContext))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<BrowsingContext>(),
+ 1usize,
+ concat!("Alignment of ", stringify!(BrowsingContext))
+ );
+}
diff --git a/tests/headers/bug-1529681.hpp b/tests/headers/bug-1529681.hpp
new file mode 100644
index 00000000..17fa849a
--- /dev/null
+++ b/tests/headers/bug-1529681.hpp
@@ -0,0 +1,8 @@
+// bindgen-flags: -- -std=c++14
+//
+// https://bugzilla.mozilla.org/show_bug.cgi?id=1529681
+// https://bugs.llvm.org/show_bug.cgi?id=40813
+
+class BrowsingContext {
+ auto Tie(void* aUnused) const;
+};