44/// For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
55/// see design document in the tracking issue #89653.
66use bitflags:: bitflags;
7- use rustc_middle:: ty:: { Instance , Ty , TyCtxt } ;
7+ use rustc_middle:: ty:: { Instance , List , Ty , TyCtxt } ;
88use rustc_target:: abi:: call:: FnAbi ;
99use std:: hash:: Hasher ;
1010use twox_hash:: XxHash64 ;
@@ -27,7 +27,11 @@ pub fn typeid_for_fnabi<'tcx>(
2727 fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
2828 options : TypeIdOptions ,
2929) -> String {
30- typeid_itanium_cxx_abi:: typeid_for_fnabi ( tcx, fn_abi, options)
30+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
31+ tcx,
32+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, None ) ,
33+ options,
34+ )
3135}
3236
3337/// Returns a type metadata identifier for the specified Instance.
@@ -36,7 +40,16 @@ pub fn typeid_for_instance<'tcx>(
3640 instance : & Instance < ' tcx > ,
3741 options : TypeIdOptions ,
3842) -> String {
39- typeid_itanium_cxx_abi:: typeid_for_instance ( tcx, instance, options)
43+ let fn_abi = tcx
44+ . fn_abi_of_instance ( tcx. param_env ( instance. def_id ( ) ) . and ( ( * instance, List :: empty ( ) ) ) )
45+ . unwrap_or_else ( |instance| {
46+ bug ! ( "typeid_for_instance: couldn't get fn_abi of instance {:?}" , instance)
47+ } ) ;
48+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
49+ tcx,
50+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, Some ( instance) ) ,
51+ options,
52+ )
4053}
4154
4255/// Returns a KCFI type metadata identifier for the specified FnAbi.
@@ -48,7 +61,14 @@ pub fn kcfi_typeid_for_fnabi<'tcx>(
4861 // A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
4962 // xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
5063 let mut hash: XxHash64 = Default :: default ( ) ;
51- hash. write ( typeid_itanium_cxx_abi:: typeid_for_fnabi ( tcx, fn_abi, options) . as_bytes ( ) ) ;
64+ hash. write (
65+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
66+ tcx,
67+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, None ) ,
68+ options,
69+ )
70+ . as_bytes ( ) ,
71+ ) ;
5272 hash. finish ( ) as u32
5373}
5474
@@ -58,9 +78,21 @@ pub fn kcfi_typeid_for_instance<'tcx>(
5878 instance : & Instance < ' tcx > ,
5979 options : TypeIdOptions ,
6080) -> u32 {
81+ let fn_abi = tcx
82+ . fn_abi_of_instance ( tcx. param_env ( instance. def_id ( ) ) . and ( ( * instance, List :: empty ( ) ) ) )
83+ . unwrap_or_else ( |instance| {
84+ bug ! ( "typeid_for_instance: couldn't get fn_abi of instance {:?}" , instance)
85+ } ) ;
6186 // A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
6287 // xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
6388 let mut hash: XxHash64 = Default :: default ( ) ;
64- hash. write ( typeid_itanium_cxx_abi:: typeid_for_instance ( tcx, instance, options) . as_bytes ( ) ) ;
89+ hash. write (
90+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
91+ tcx,
92+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, Some ( instance) ) ,
93+ options,
94+ )
95+ . as_bytes ( ) ,
96+ ) ;
6597 hash. finish ( ) as u32
6698}
0 commit comments