@@ -19,9 +19,12 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
19
19
use rustc_middle:: ty:: layout:: {
20
20
FnAbiError , FnAbiOfHelpers , FnAbiRequest , LayoutError , LayoutOfHelpers , TyAndLayout ,
21
21
} ;
22
- use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
22
+ use rustc_middle:: ty:: { self , Instance , Ty , TyCtxt } ;
23
23
use 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
+ } ;
25
28
use rustc_target:: abi:: { self , call:: FnAbi , Align , Size , WrappingRange } ;
26
29
use rustc_target:: spec:: { HasTargetSpec , SanitizerSet , Target } ;
27
30
use smallvec:: SmallVec ;
@@ -221,6 +224,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
221
224
then : & ' ll BasicBlock ,
222
225
catch : & ' ll BasicBlock ,
223
226
funclet : Option < & Funclet < ' ll > > ,
227
+ instance : Option < Instance < ' tcx > > ,
224
228
) -> & ' ll Value {
225
229
debug ! ( "invoke {:?} with args ({:?})" , llfn, args) ;
226
230
@@ -233,10 +237,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
233
237
}
234
238
235
239
// 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) ;
237
241
238
242
// 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) ;
240
244
let kcfi_bundle = kcfi_bundle. as_ref ( ) . map ( |b| & * b. raw ) ;
241
245
if let Some ( kcfi_bundle) = kcfi_bundle {
242
246
bundles. push ( kcfi_bundle) ;
@@ -1231,6 +1235,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
1231
1235
llfn : & ' ll Value ,
1232
1236
args : & [ & ' ll Value ] ,
1233
1237
funclet : Option < & Funclet < ' ll > > ,
1238
+ instance : Option < Instance < ' tcx > > ,
1234
1239
) -> & ' ll Value {
1235
1240
debug ! ( "call {:?} with args ({:?})" , llfn, args) ;
1236
1241
@@ -1243,10 +1248,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
1243
1248
}
1244
1249
1245
1250
// 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) ;
1247
1252
1248
1253
// 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) ;
1250
1255
let kcfi_bundle = kcfi_bundle. as_ref ( ) . map ( |b| & * b. raw ) ;
1251
1256
if let Some ( kcfi_bundle) = kcfi_bundle {
1252
1257
bundles. push ( kcfi_bundle) ;
@@ -1468,7 +1473,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
1468
1473
1469
1474
pub ( crate ) fn call_intrinsic ( & mut self , intrinsic : & str , args : & [ & ' ll Value ] ) -> & ' ll Value {
1470
1475
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 )
1472
1477
}
1473
1478
1474
1479
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> {
1526
1531
format ! ( "llvm.{instr}.sat.i{int_width}.f{float_width}" )
1527
1532
} ;
1528
1533
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 )
1530
1535
}
1531
1536
1532
1537
pub ( crate ) fn landing_pad (
@@ -1554,6 +1559,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
1554
1559
default_dest : & ' ll BasicBlock ,
1555
1560
indirect_dest : & [ & ' ll BasicBlock ] ,
1556
1561
funclet : Option < & Funclet < ' ll > > ,
1562
+ instance : Option < Instance < ' tcx > > ,
1557
1563
) -> & ' ll Value {
1558
1564
debug ! ( "invoke {:?} with args ({:?})" , llfn, args) ;
1559
1565
@@ -1566,10 +1572,10 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
1566
1572
}
1567
1573
1568
1574
// 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) ;
1570
1576
1571
1577
// 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) ;
1573
1579
let kcfi_bundle = kcfi_bundle. as_ref ( ) . map ( |b| & * b. raw ) ;
1574
1580
if let Some ( kcfi_bundle) = kcfi_bundle {
1575
1581
bundles. push ( kcfi_bundle) ;
@@ -1601,6 +1607,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
1601
1607
& mut self ,
1602
1608
fn_attrs : Option < & CodegenFnAttrs > ,
1603
1609
fn_abi : Option < & FnAbi < ' tcx , Ty < ' tcx > > > ,
1610
+ instance : Option < Instance < ' tcx > > ,
1604
1611
llfn : & ' ll Value ,
1605
1612
) {
1606
1613
let is_indirect_call = unsafe { llvm:: LLVMRustIsNonGVFunctionPointerTy ( llfn) } ;
@@ -1622,7 +1629,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
1622
1629
options. insert ( TypeIdOptions :: NORMALIZE_INTEGERS ) ;
1623
1630
}
1624
1631
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
+ } ;
1626
1637
let typeid_metadata = self . cx . typeid_metadata ( typeid) . unwrap ( ) ;
1627
1638
1628
1639
// Test whether the function pointer is associated with the type identifier.
@@ -1644,6 +1655,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
1644
1655
& mut self ,
1645
1656
fn_attrs : Option < & CodegenFnAttrs > ,
1646
1657
fn_abi : Option < & FnAbi < ' tcx , Ty < ' tcx > > > ,
1658
+ instance : Option < Instance < ' tcx > > ,
1647
1659
llfn : & ' ll Value ,
1648
1660
) -> Option < llvm:: OperandBundleDef < ' ll > > {
1649
1661
let is_indirect_call = unsafe { llvm:: LLVMRustIsNonGVFunctionPointerTy ( llfn) } ;
@@ -1665,7 +1677,12 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
1665
1677
options. insert ( TypeIdOptions :: NORMALIZE_INTEGERS ) ;
1666
1678
}
1667
1679
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
+
1669
1686
Some ( llvm:: OperandBundleDef :: new ( "kcfi" , & [ self . const_u32 ( kcfi_typeid) ] ) )
1670
1687
} else {
1671
1688
None
0 commit comments