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:: { FnSig , 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 ;
@@ -26,16 +26,11 @@ pub fn typeid_for_fnabi<'tcx>(
2626 fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
2727 options : TypeIdOptions ,
2828) -> String {
29- typeid_itanium_cxx_abi:: typeid_for_fnabi ( tcx, fn_abi, options)
30- }
31-
32- /// Returns a type metadata identifier for the specified FnSig.
33- pub fn typeid_for_fnsig < ' tcx > (
34- tcx : TyCtxt < ' tcx > ,
35- fn_sig : & FnSig < ' tcx > ,
36- options : TypeIdOptions ,
37- ) -> String {
38- typeid_itanium_cxx_abi:: typeid_for_fnsig ( tcx, fn_sig, options)
29+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
30+ tcx,
31+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, None ) ,
32+ options,
33+ )
3934}
4035
4136/// Returns a type metadata identifier for the specified Instance.
@@ -44,7 +39,16 @@ pub fn typeid_for_instance<'tcx>(
4439 instance : & Instance < ' tcx > ,
4540 options : TypeIdOptions ,
4641) -> String {
47- typeid_itanium_cxx_abi:: typeid_for_instance ( tcx, instance, options)
42+ let fn_abi = tcx
43+ . fn_abi_of_instance ( tcx. param_env ( instance. def_id ( ) ) . and ( ( * instance, List :: empty ( ) ) ) )
44+ . unwrap_or_else ( |instance| {
45+ bug ! ( "typeid_for_instance: couldn't get fn_abi of instance {:?}" , instance)
46+ } ) ;
47+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
48+ tcx,
49+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, Some ( instance) ) ,
50+ options,
51+ )
4852}
4953
5054/// Returns a KCFI type metadata identifier for the specified FnAbi.
@@ -56,20 +60,14 @@ pub fn kcfi_typeid_for_fnabi<'tcx>(
5660 // A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
5761 // xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
5862 let mut hash: XxHash64 = Default :: default ( ) ;
59- hash. write ( typeid_itanium_cxx_abi:: typeid_for_fnabi ( tcx, fn_abi, options) . as_bytes ( ) ) ;
60- hash. finish ( ) as u32
61- }
62-
63- /// Returns a KCFI type metadata identifier for the specified FnSig.
64- pub fn kcfi_typeid_for_fnsig < ' tcx > (
65- tcx : TyCtxt < ' tcx > ,
66- fn_sig : & FnSig < ' tcx > ,
67- options : TypeIdOptions ,
68- ) -> u32 {
69- // A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
70- // xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
71- let mut hash: XxHash64 = Default :: default ( ) ;
72- hash. write ( typeid_itanium_cxx_abi:: typeid_for_fnsig ( tcx, fn_sig, options) . as_bytes ( ) ) ;
63+ hash. write (
64+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
65+ tcx,
66+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, None ) ,
67+ options,
68+ )
69+ . as_bytes ( ) ,
70+ ) ;
7371 hash. finish ( ) as u32
7472}
7573
@@ -79,9 +77,21 @@ pub fn kcfi_typeid_for_instance<'tcx>(
7977 instance : & Instance < ' tcx > ,
8078 options : TypeIdOptions ,
8179) -> u32 {
80+ let fn_abi = tcx
81+ . fn_abi_of_instance ( tcx. param_env ( instance. def_id ( ) ) . and ( ( * instance, List :: empty ( ) ) ) )
82+ . unwrap_or_else ( |instance| {
83+ bug ! ( "typeid_for_instance: couldn't get fn_abi of instance {:?}" , instance)
84+ } ) ;
8285 // A KCFI type metadata identifier is a 32-bit constant produced by taking the lower half of the
8386 // xxHash64 of the type metadata identifier. (See llvm/llvm-project@cff5bef.)
8487 let mut hash: XxHash64 = Default :: default ( ) ;
85- hash. write ( typeid_itanium_cxx_abi:: typeid_for_instance ( tcx, instance, options) . as_bytes ( ) ) ;
88+ hash. write (
89+ typeid_itanium_cxx_abi:: typeid_for_fnabi (
90+ tcx,
91+ & typeid_itanium_cxx_abi:: transform_fnabi ( tcx, & fn_abi, options, Some ( instance) ) ,
92+ options,
93+ )
94+ . as_bytes ( ) ,
95+ ) ;
8696 hash. finish ( ) as u32
8797}
0 commit comments