@@ -19,9 +19,12 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
1919use  rustc_middle:: ty:: layout:: { 
2020    FnAbiError ,  FnAbiOfHelpers ,  FnAbiRequest ,  LayoutError ,  LayoutOfHelpers ,  TyAndLayout , 
2121} ; 
22- use  rustc_middle:: ty:: { self ,  Ty ,  TyCtxt } ; 
22+ use  rustc_middle:: ty:: { self ,  Instance ,   Ty ,  TyCtxt } ; 
2323use  rustc_span:: Span ; 
24- use  rustc_symbol_mangling:: typeid:: { kcfi_typeid_for_fnabi,  typeid_for_fnabi,  TypeIdOptions } ; 
24+ use  rustc_symbol_mangling:: typeid:: { 
25+     kcfi_typeid_for_fnabi,  kcfi_typeid_for_instance,  typeid_for_fnabi,  typeid_for_instance, 
26+     TypeIdOptions , 
27+ } ; 
2528use  rustc_target:: abi:: { self ,  call:: FnAbi ,  Align ,  Size ,  WrappingRange } ; 
2629use  rustc_target:: spec:: { HasTargetSpec ,  SanitizerSet ,  Target } ; 
2730use  smallvec:: SmallVec ; 
@@ -221,6 +224,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
221224        then :  & ' ll  BasicBlock , 
222225        catch :  & ' ll  BasicBlock , 
223226        funclet :  Option < & Funclet < ' ll > > , 
227+         instance :  Option < Instance < ' tcx > > , 
224228    )  -> & ' ll  Value  { 
225229        debug ! ( "invoke {:?} with args ({:?})" ,  llfn,  args) ; 
226230
@@ -233,10 +237,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
233237        } 
234238
235239        // Emit CFI pointer type membership test 
236-         self . cfi_type_test ( fn_attrs,  fn_abi,  llfn) ; 
240+         self . cfi_type_test ( fn_attrs,  fn_abi,  instance ,   llfn) ; 
237241
238242        // Emit KCFI operand bundle 
239-         let  kcfi_bundle = self . kcfi_operand_bundle ( fn_attrs,  fn_abi,  llfn) ; 
243+         let  kcfi_bundle = self . kcfi_operand_bundle ( fn_attrs,  fn_abi,  instance ,   llfn) ; 
240244        let  kcfi_bundle = kcfi_bundle. as_ref ( ) . map ( |b| & * b. raw ) ; 
241245        if  let  Some ( kcfi_bundle)  = kcfi_bundle { 
242246            bundles. push ( kcfi_bundle) ; 
@@ -1231,6 +1235,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12311235        llfn :  & ' ll  Value , 
12321236        args :  & [ & ' ll  Value ] , 
12331237        funclet :  Option < & Funclet < ' ll > > , 
1238+         instance :  Option < Instance < ' tcx > > , 
12341239    )  -> & ' ll  Value  { 
12351240        debug ! ( "call {:?} with args ({:?})" ,  llfn,  args) ; 
12361241
@@ -1243,10 +1248,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12431248        } 
12441249
12451250        // Emit CFI pointer type membership test 
1246-         self . cfi_type_test ( fn_attrs,  fn_abi,  llfn) ; 
1251+         self . cfi_type_test ( fn_attrs,  fn_abi,  instance ,   llfn) ; 
12471252
12481253        // Emit KCFI operand bundle 
1249-         let  kcfi_bundle = self . kcfi_operand_bundle ( fn_attrs,  fn_abi,  llfn) ; 
1254+         let  kcfi_bundle = self . kcfi_operand_bundle ( fn_attrs,  fn_abi,  instance ,   llfn) ; 
12501255        let  kcfi_bundle = kcfi_bundle. as_ref ( ) . map ( |b| & * b. raw ) ; 
12511256        if  let  Some ( kcfi_bundle)  = kcfi_bundle { 
12521257            bundles. push ( kcfi_bundle) ; 
@@ -1468,7 +1473,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
14681473
14691474    pub ( crate )  fn  call_intrinsic ( & mut  self ,  intrinsic :  & str ,  args :  & [ & ' ll  Value ] )  -> & ' ll  Value  { 
14701475        let  ( ty,  f)  = self . cx . get_intrinsic ( intrinsic) ; 
1471-         self . call ( ty,  None ,  None ,  f,  args,  None ) 
1476+         self . call ( ty,  None ,  None ,  f,  args,  None ,   None ) 
14721477    } 
14731478
14741479    fn  call_lifetime_intrinsic ( & mut  self ,  intrinsic :  & str ,  ptr :  & ' ll  Value ,  size :  Size )  { 
@@ -1526,7 +1531,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15261531            format ! ( "llvm.{instr}.sat.i{int_width}.f{float_width}" ) 
15271532        } ; 
15281533        let  f = self . declare_cfn ( & name,  llvm:: UnnamedAddr :: No ,  self . type_func ( & [ src_ty] ,  dest_ty) ) ; 
1529-         self . call ( self . type_func ( & [ src_ty] ,  dest_ty) ,  None ,  None ,  f,  & [ val] ,  None ) 
1534+         self . call ( self . type_func ( & [ src_ty] ,  dest_ty) ,  None ,  None ,  f,  & [ val] ,  None ,   None ) 
15301535    } 
15311536
15321537    pub ( crate )  fn  landing_pad ( 
@@ -1554,6 +1559,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15541559        default_dest :  & ' ll  BasicBlock , 
15551560        indirect_dest :  & [ & ' ll  BasicBlock ] , 
15561561        funclet :  Option < & Funclet < ' ll > > , 
1562+         instance :  Option < Instance < ' tcx > > , 
15571563    )  -> & ' ll  Value  { 
15581564        debug ! ( "invoke {:?} with args ({:?})" ,  llfn,  args) ; 
15591565
@@ -1566,10 +1572,10 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15661572        } 
15671573
15681574        // Emit CFI pointer type membership test 
1569-         self . cfi_type_test ( fn_attrs,  fn_abi,  llfn) ; 
1575+         self . cfi_type_test ( fn_attrs,  fn_abi,  instance ,   llfn) ; 
15701576
15711577        // Emit KCFI operand bundle 
1572-         let  kcfi_bundle = self . kcfi_operand_bundle ( fn_attrs,  fn_abi,  llfn) ; 
1578+         let  kcfi_bundle = self . kcfi_operand_bundle ( fn_attrs,  fn_abi,  instance ,   llfn) ; 
15731579        let  kcfi_bundle = kcfi_bundle. as_ref ( ) . map ( |b| & * b. raw ) ; 
15741580        if  let  Some ( kcfi_bundle)  = kcfi_bundle { 
15751581            bundles. push ( kcfi_bundle) ; 
@@ -1601,6 +1607,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16011607        & mut  self , 
16021608        fn_attrs :  Option < & CodegenFnAttrs > , 
16031609        fn_abi :  Option < & FnAbi < ' tcx ,  Ty < ' tcx > > > , 
1610+         instance :  Option < Instance < ' tcx > > , 
16041611        llfn :  & ' ll  Value , 
16051612    )  { 
16061613        let  is_indirect_call = unsafe  {  llvm:: LLVMRustIsNonGVFunctionPointerTy ( llfn)  } ; 
@@ -1622,7 +1629,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16221629                options. insert ( TypeIdOptions :: NORMALIZE_INTEGERS ) ; 
16231630            } 
16241631
1625-             let  typeid = typeid_for_fnabi ( self . tcx ,  fn_abi,  options) ; 
1632+             let  typeid = if  let  Some ( instance)  = instance { 
1633+                 typeid_for_instance ( self . tcx ,  & instance,  options) 
1634+             }  else  { 
1635+                 typeid_for_fnabi ( self . tcx ,  fn_abi,  options) 
1636+             } ; 
16261637            let  typeid_metadata = self . cx . typeid_metadata ( typeid) . unwrap ( ) ; 
16271638
16281639            // Test whether the function pointer is associated with the type identifier. 
@@ -1644,6 +1655,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16441655        & mut  self , 
16451656        fn_attrs :  Option < & CodegenFnAttrs > , 
16461657        fn_abi :  Option < & FnAbi < ' tcx ,  Ty < ' tcx > > > , 
1658+         instance :  Option < Instance < ' tcx > > , 
16471659        llfn :  & ' ll  Value , 
16481660    )  -> Option < llvm:: OperandBundleDef < ' ll > >  { 
16491661        let  is_indirect_call = unsafe  {  llvm:: LLVMRustIsNonGVFunctionPointerTy ( llfn)  } ; 
@@ -1665,7 +1677,12 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16651677                options. insert ( TypeIdOptions :: NORMALIZE_INTEGERS ) ; 
16661678            } 
16671679
1668-             let  kcfi_typeid = kcfi_typeid_for_fnabi ( self . tcx ,  fn_abi,  options) ; 
1680+             let  kcfi_typeid = if  let  Some ( instance)  = instance { 
1681+                 kcfi_typeid_for_instance ( self . tcx ,  & instance,  options) 
1682+             }  else  { 
1683+                 kcfi_typeid_for_fnabi ( self . tcx ,  fn_abi,  options) 
1684+             } ; 
1685+ 
16691686            Some ( llvm:: OperandBundleDef :: new ( "kcfi" ,  & [ self . const_u32 ( kcfi_typeid) ] ) ) 
16701687        }  else  { 
16711688            None 
0 commit comments