@@ -18,7 +18,9 @@ use crate::llvm;
18
18
use crate :: llvm:: AttributePlace :: Function ;
19
19
use crate :: type_:: Type ;
20
20
use crate :: value:: Value ;
21
+ use itertools:: Itertools ;
21
22
use rustc_codegen_ssa:: traits:: TypeMembershipMethods ;
23
+ use rustc_data_structures:: fx:: FxIndexSet ;
22
24
use rustc_middle:: ty:: { Instance , Ty } ;
23
25
use rustc_symbol_mangling:: typeid:: {
24
26
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
@@ -141,33 +143,31 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
141
143
142
144
if self . tcx . sess . is_sanitizer_cfi_enabled ( ) {
143
145
if let Some ( instance) = instance {
144
- let typeid = typeid_for_instance ( self . tcx , instance, TypeIdOptions :: empty ( ) ) ;
145
- self . set_type_metadata ( llfn, typeid) ;
146
- let typeid =
147
- typeid_for_instance ( self . tcx , instance, TypeIdOptions :: GENERALIZE_POINTERS ) ;
148
- self . add_type_metadata ( llfn, typeid) ;
149
- let typeid =
150
- typeid_for_instance ( self . tcx , instance, TypeIdOptions :: NORMALIZE_INTEGERS ) ;
151
- self . add_type_metadata ( llfn, typeid) ;
152
- let typeid = typeid_for_instance (
153
- self . tcx ,
154
- instance,
155
- TypeIdOptions :: GENERALIZE_POINTERS | TypeIdOptions :: NORMALIZE_INTEGERS ,
156
- ) ;
157
- self . add_type_metadata ( llfn, typeid) ;
146
+ let mut typeids = FxIndexSet :: default ( ) ;
147
+ for options in [
148
+ TypeIdOptions :: GENERALIZE_POINTERS ,
149
+ TypeIdOptions :: NORMALIZE_INTEGERS ,
150
+ TypeIdOptions :: NO_SELF_TYPE_ERASURE ,
151
+ ]
152
+ . into_iter ( )
153
+ . powerset ( )
154
+ . map ( TypeIdOptions :: from_iter)
155
+ {
156
+ let typeid = typeid_for_instance ( self . tcx , instance, options) ;
157
+ if typeids. insert ( typeid. clone ( ) ) {
158
+ self . add_type_metadata ( llfn, typeid) ;
159
+ }
160
+ }
158
161
} else {
159
- let typeid = typeid_for_fnabi ( self . tcx , fn_abi, TypeIdOptions :: empty ( ) ) ;
160
- self . set_type_metadata ( llfn, typeid) ;
161
- let typeid = typeid_for_fnabi ( self . tcx , fn_abi, TypeIdOptions :: GENERALIZE_POINTERS ) ;
162
- self . add_type_metadata ( llfn, typeid) ;
163
- let typeid = typeid_for_fnabi ( self . tcx , fn_abi, TypeIdOptions :: NORMALIZE_INTEGERS ) ;
164
- self . add_type_metadata ( llfn, typeid) ;
165
- let typeid = typeid_for_fnabi (
166
- self . tcx ,
167
- fn_abi,
168
- TypeIdOptions :: GENERALIZE_POINTERS | TypeIdOptions :: NORMALIZE_INTEGERS ,
169
- ) ;
170
- self . add_type_metadata ( llfn, typeid) ;
162
+ for options in
163
+ [ TypeIdOptions :: GENERALIZE_POINTERS , TypeIdOptions :: NORMALIZE_INTEGERS ]
164
+ . into_iter ( )
165
+ . powerset ( )
166
+ . map ( TypeIdOptions :: from_iter)
167
+ {
168
+ let typeid = typeid_for_fnabi ( self . tcx , fn_abi, options) ;
169
+ self . add_type_metadata ( llfn, typeid) ;
170
+ }
171
171
}
172
172
}
173
173
0 commit comments