@@ -213,7 +213,8 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
213
213
}
214
214
215
215
/// Overwrites all provenance in the given range with wildcard provenance.
216
- /// Pointers partially overwritten will have their provenances
216
+ /// Pointers partially overwritten will have their provenances preserved
217
+ /// bytewise on their remaining bytes.
217
218
///
218
219
/// Provided for usage in Miri and panics otherwise.
219
220
pub fn write_wildcards ( & mut self , cx : & impl HasDataLayout , range : AllocRange ) {
@@ -223,25 +224,27 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
223
224
) ;
224
225
let wildcard = Prov :: WILDCARD . unwrap ( ) ;
225
226
226
- // Get pointer provenances that overlap with the range, then remove them.
227
+ let bytes = self . bytes . get_or_insert_with ( Box :: default) ;
228
+
229
+ // Remove pointer provenances that overlap with the range, then readd the edge ones bytewise.
227
230
let ptr_range = Self :: adjusted_range_ptrs ( range, cx) ;
228
- let removed = ptr_range. filter_map ( |i| self . ptrs . remove ( & i) . map ( |p| ( i, p) ) ) ;
231
+ let ptrs = self . ptrs . range ( ptr_range. clone ( ) ) ;
232
+ if let Some ( ( offset, prov) ) = ptrs. first ( ) {
233
+ for byte_ofs in * offset..range. start {
234
+ bytes. insert ( byte_ofs, * prov) ;
235
+ }
236
+ }
237
+ if let Some ( ( offset, prov) ) = ptrs. last ( ) {
238
+ for byte_ofs in range. end ( ) ..* offset + cx. data_layout ( ) . pointer_size ( ) {
239
+ bytes. insert ( byte_ofs, * prov) ;
240
+ }
241
+ }
242
+ self . ptrs . remove_range ( ptr_range) ;
243
+
229
244
// Overwrite bytewise provenance.
230
- let bytes = self . bytes . get_or_insert_with ( Box :: default) ;
231
245
for offset in range. start ..range. end ( ) {
232
246
bytes. insert ( offset, wildcard) ;
233
247
}
234
- // Now readd pointer provenances that were only partly overwritten. Always
235
- // check both the start and end to allow for a write to happen in the middle
236
- // of a pointer.
237
- for ( rm_ofs, prov) in removed {
238
- for head_ofs in rm_ofs..range. start {
239
- bytes. insert ( head_ofs, prov) ;
240
- }
241
- for tail_ofs in range. end ( ) ..rm_ofs + cx. data_layout ( ) . pointer_size ( ) {
242
- bytes. insert ( tail_ofs, prov) ;
243
- }
244
- }
245
248
}
246
249
}
247
250
0 commit comments