@@ -1525,9 +1525,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15251525 fn_abi : Option < & FnAbi < ' tcx , Ty < ' tcx > > > ,
15261526 llfn : & ' ll Value ,
15271527 ) {
1528- let is_indirect_call = unsafe { llvm:: LLVMIsAFunction ( llfn) . is_none ( ) } ;
1529- if is_indirect_call && fn_abi . is_some ( ) && self . tcx . sess . is_sanitizer_cfi_enabled ( ) {
1530- if fn_attrs . is_some ( ) && fn_attrs. unwrap ( ) . no_sanitize . contains ( SanitizerSet :: CFI ) {
1528+ let is_indirect_call = unsafe { llvm:: LLVMRustIsNonGVFunctionPointerTy ( llfn) } ;
1529+ if self . tcx . sess . is_sanitizer_cfi_enabled ( ) && let Some ( fn_abi ) = fn_abi && is_indirect_call {
1530+ if let Some ( fn_attrs ) = fn_attrs && fn_attrs. no_sanitize . contains ( SanitizerSet :: CFI ) {
15311531 return ;
15321532 }
15331533
@@ -1539,7 +1539,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15391539 options. insert ( TypeIdOptions :: NORMALIZE_INTEGERS ) ;
15401540 }
15411541
1542- let typeid = typeid_for_fnabi ( self . tcx , fn_abi. unwrap ( ) , options) ;
1542+ let typeid = typeid_for_fnabi ( self . tcx , fn_abi, options) ;
15431543 let typeid_metadata = self . cx . typeid_metadata ( typeid) . unwrap ( ) ;
15441544
15451545 // Test whether the function pointer is associated with the type identifier.
@@ -1563,25 +1563,26 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15631563 fn_abi : Option < & FnAbi < ' tcx , Ty < ' tcx > > > ,
15641564 llfn : & ' ll Value ,
15651565 ) -> Option < llvm:: OperandBundleDef < ' ll > > {
1566- let is_indirect_call = unsafe { llvm:: LLVMIsAFunction ( llfn) . is_none ( ) } ;
1567- let kcfi_bundle = if is_indirect_call && self . tcx . sess . is_sanitizer_kcfi_enabled ( ) {
1568- if fn_attrs. is_some ( ) && fn_attrs. unwrap ( ) . no_sanitize . contains ( SanitizerSet :: KCFI ) {
1569- return None ;
1570- }
1566+ let is_indirect_call = unsafe { llvm:: LLVMRustIsNonGVFunctionPointerTy ( llfn) } ;
1567+ let kcfi_bundle =
1568+ if self . tcx . sess . is_sanitizer_kcfi_enabled ( ) && let Some ( fn_abi) = fn_abi && is_indirect_call {
1569+ if let Some ( fn_attrs) = fn_attrs && fn_attrs. no_sanitize . contains ( SanitizerSet :: KCFI ) {
1570+ return None ;
1571+ }
15711572
1572- let mut options = TypeIdOptions :: empty ( ) ;
1573- if self . tcx . sess . is_sanitizer_cfi_generalize_pointers_enabled ( ) {
1574- options. insert ( TypeIdOptions :: GENERALIZE_POINTERS ) ;
1575- }
1576- if self . tcx . sess . is_sanitizer_cfi_normalize_integers_enabled ( ) {
1577- options. insert ( TypeIdOptions :: NORMALIZE_INTEGERS ) ;
1578- }
1573+ let mut options = TypeIdOptions :: empty ( ) ;
1574+ if self . tcx . sess . is_sanitizer_cfi_generalize_pointers_enabled ( ) {
1575+ options. insert ( TypeIdOptions :: GENERALIZE_POINTERS ) ;
1576+ }
1577+ if self . tcx . sess . is_sanitizer_cfi_normalize_integers_enabled ( ) {
1578+ options. insert ( TypeIdOptions :: NORMALIZE_INTEGERS ) ;
1579+ }
15791580
1580- let kcfi_typeid = kcfi_typeid_for_fnabi ( self . tcx , fn_abi. unwrap ( ) , options) ;
1581- Some ( llvm:: OperandBundleDef :: new ( "kcfi" , & [ self . const_u32 ( kcfi_typeid) ] ) )
1582- } else {
1583- None
1584- } ;
1581+ let kcfi_typeid = kcfi_typeid_for_fnabi ( self . tcx , fn_abi, options) ;
1582+ Some ( llvm:: OperandBundleDef :: new ( "kcfi" , & [ self . const_u32 ( kcfi_typeid) ] ) )
1583+ } else {
1584+ None
1585+ } ;
15851586 kcfi_bundle
15861587 }
15871588}
0 commit comments