@@ -931,18 +931,37 @@ impl Type {
931
931
unsafe { clang_isConstQualifiedType ( self . x ) != 0 }
932
932
}
933
933
934
+ #[ inline]
935
+ fn is_non_deductible_auto_type ( & self ) -> bool {
936
+ self . kind ( ) == CXType_Auto && self . canonical_type ( ) == * self
937
+ }
938
+
939
+ #[ inline]
940
+ fn clang_size_of ( & self ) -> c_longlong {
941
+ if self . is_non_deductible_auto_type ( ) {
942
+ return -6 ; // Work-around https://bugs.llvm.org/show_bug.cgi?id=40813
943
+ }
944
+ unsafe { clang_Type_getSizeOf ( self . x ) }
945
+ }
946
+
947
+ #[ inline]
948
+ fn clang_align_of ( & self ) -> c_longlong {
949
+ if self . is_non_deductible_auto_type ( ) {
950
+ return -6 ; // Work-around https://bugs.llvm.org/show_bug.cgi?id=40813
951
+ }
952
+ unsafe { clang_Type_getAlignOf ( self . x ) }
953
+ }
954
+
934
955
/// What is the size of this type? Paper over invalid types by returning `0`
935
956
/// for them.
936
957
pub fn size ( & self ) -> usize {
937
- unsafe {
938
- let val = clang_Type_getSizeOf ( self . x ) ;
939
- if val < 0 { 0 } else { val as usize }
940
- }
958
+ let val = self . clang_size_of ( ) ;
959
+ if val < 0 { 0 } else { val as usize }
941
960
}
942
961
943
962
/// What is the size of this type?
944
963
pub fn fallible_size ( & self ) -> Result < usize , LayoutError > {
945
- let val = unsafe { clang_Type_getSizeOf ( self . x ) } ;
964
+ let val = self . clang_size_of ( ) ;
946
965
if val < 0 {
947
966
Err ( LayoutError :: from ( val as i32 ) )
948
967
} else {
@@ -953,21 +972,17 @@ impl Type {
953
972
/// What is the alignment of this type? Paper over invalid types by
954
973
/// returning `0`.
955
974
pub fn align ( & self ) -> usize {
956
- unsafe {
957
- let val = clang_Type_getAlignOf ( self . x ) ;
958
- if val < 0 { 0 } else { val as usize }
959
- }
975
+ let val = self . clang_align_of ( ) ;
976
+ if val < 0 { 0 } else { val as usize }
960
977
}
961
978
962
979
/// What is the alignment of this type?
963
980
pub fn fallible_align ( & self ) -> Result < usize , LayoutError > {
964
- unsafe {
965
- let val = clang_Type_getAlignOf ( self . x ) ;
966
- if val < 0 {
967
- Err ( LayoutError :: from ( val as i32 ) )
968
- } else {
969
- Ok ( val as usize )
970
- }
981
+ let val = self . clang_align_of ( ) ;
982
+ if val < 0 {
983
+ Err ( LayoutError :: from ( val as i32 ) )
984
+ } else {
985
+ Ok ( val as usize )
971
986
}
972
987
}
973
988
0 commit comments