summaryrefslogtreecommitdiff
path: root/src/clang.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2019-02-23 06:59:43 +0100
committerGitHub <noreply@github.com>2019-02-23 06:59:43 +0100
commitf4f47d52cbce45af177958e76ef9a4a17e922bc4 (patch)
tree4cbdf487f5af7913478cae56aa678e73c468fd73 /src/clang.rs
parent9fb016e32bfc2cd917c907e8b9e892eed89b24c7 (diff)
parent592c7cb5eb1a2578464bf6d4892546f7e0bf4b4b (diff)
Merge pull request #1525 from emilio/llvm-bug-workaroundv0.47.2
Work-around https://bugs.llvm.org/show_bug.cgi?id=40813.
Diffstat (limited to 'src/clang.rs')
-rw-r--r--src/clang.rs47
1 files changed, 31 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)
}
}