@@ -60,21 +60,12 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
60
60
pub fn check_bounds_ptr (
61
61
& self ,
62
62
ptr : Pointer < Tag > ,
63
- check : InboundsCheck ,
64
63
) -> EvalResult < ' tcx > {
65
- let allocation_size = match check {
66
- InboundsCheck :: Live => {
67
- let alloc = self . get ( ptr. alloc_id ) ?;
68
- alloc. bytes . len ( ) as u64
69
- }
70
- InboundsCheck :: MaybeDead => {
71
- self . get_size_and_align ( ptr. alloc_id ) . 0 . bytes ( )
72
- }
73
- } ;
64
+ let allocation_size = self . bytes . len ( ) as u64 ;
74
65
if ptr. offset . bytes ( ) > allocation_size {
75
66
return err ! ( PointerOutOfBounds {
76
67
ptr: ptr. erase_tag( ) ,
77
- check,
68
+ check: InboundsCheck :: Live ,
78
69
allocation_size: Size :: from_bytes( allocation_size) ,
79
70
} ) ;
80
71
}
@@ -87,15 +78,14 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
87
78
& self ,
88
79
ptr : Pointer < Tag > ,
89
80
size : Size ,
90
- check : InboundsCheck ,
91
81
) -> EvalResult < ' tcx > {
92
82
// if ptr.offset is in bounds, then so is ptr (because offset checks for overflow)
93
- self . check_bounds_ptr ( ptr. offset ( size, & * self ) ?, check )
83
+ self . check_bounds_ptr ( ptr. offset ( size, & * self ) ?)
94
84
}
95
85
}
96
86
97
87
/// Byte accessors
98
- impl < ' tcx , Tag , Extra > Allocation < Tag , Extra > {
88
+ impl < ' tcx , Tag , Extra : AllocationExtra < Tag > > Allocation < Tag , Extra > {
99
89
/// The last argument controls whether we error out when there are undefined
100
90
/// or pointer bytes. You should never call this, call `get_bytes` or
101
91
/// `get_bytes_with_undef_and_ptr` instead,
@@ -122,13 +112,12 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
122
112
self . check_relocation_edges ( ptr, size) ?;
123
113
}
124
114
125
- let alloc = self . get ( ptr. alloc_id ) ?;
126
- AllocationExtra :: memory_read ( alloc, ptr, size) ?;
115
+ AllocationExtra :: memory_read ( self , ptr, size) ?;
127
116
128
117
assert_eq ! ( ptr. offset. bytes( ) as usize as u64 , ptr. offset. bytes( ) ) ;
129
118
assert_eq ! ( size. bytes( ) as usize as u64 , size. bytes( ) ) ;
130
119
let offset = ptr. offset . bytes ( ) as usize ;
131
- Ok ( & alloc . bytes [ offset..offset + size. bytes ( ) as usize ] )
120
+ Ok ( & self . bytes [ offset..offset + size. bytes ( ) as usize ] )
132
121
}
133
122
134
123
#[ inline]
@@ -168,13 +157,12 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
168
157
self . mark_definedness ( ptr, size, true ) ?;
169
158
self . clear_relocations ( ptr, size) ?;
170
159
171
- let alloc = self . get_mut ( ptr. alloc_id ) ?;
172
- AllocationExtra :: memory_written ( alloc, ptr, size) ?;
160
+ AllocationExtra :: memory_written ( self , ptr, size) ?;
173
161
174
162
assert_eq ! ( ptr. offset. bytes( ) as usize as u64 , ptr. offset. bytes( ) ) ;
175
163
assert_eq ! ( size. bytes( ) as usize as u64 , size. bytes( ) ) ;
176
164
let offset = ptr. offset . bytes ( ) as usize ;
177
- Ok ( & mut alloc . bytes [ offset..offset + size. bytes ( ) as usize ] )
165
+ Ok ( & mut self . bytes [ offset..offset + size. bytes ( ) as usize ] )
178
166
}
179
167
}
180
168
@@ -190,7 +178,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
190
178
// the beginning of this range.
191
179
let start = ptr. offset . bytes ( ) . saturating_sub ( self . pointer_size ( ) . bytes ( ) - 1 ) ;
192
180
let end = ptr. offset + size; // this does overflow checking
193
- Ok ( self . get ( ptr . alloc_id ) ? . relocations . range ( Size :: from_bytes ( start) ..end) )
181
+ Ok ( self . relocations . range ( Size :: from_bytes ( start) ..end) )
194
182
}
195
183
196
184
/// Check that there ar eno relocations overlapping with the given range.
@@ -224,19 +212,17 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
224
212
let start = ptr. offset ;
225
213
let end = start + size;
226
214
227
- let alloc = self . get_mut ( ptr. alloc_id ) ?;
228
-
229
215
// Mark parts of the outermost relocations as undefined if they partially fall outside the
230
216
// given range.
231
217
if first < start {
232
- alloc . undef_mask . set_range ( first, start, false ) ;
218
+ self . undef_mask . set_range ( first, start, false ) ;
233
219
}
234
220
if last > end {
235
- alloc . undef_mask . set_range ( end, last, false ) ;
221
+ self . undef_mask . set_range ( end, last, false ) ;
236
222
}
237
223
238
224
// Forget all the relocations.
239
- alloc . relocations . remove_range ( first..last) ;
225
+ self . relocations . remove_range ( first..last) ;
240
226
241
227
Ok ( ( ) )
242
228
}
@@ -258,8 +244,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
258
244
/// error which will report the first byte which is undefined.
259
245
#[ inline]
260
246
fn check_defined ( & self , ptr : Pointer < Tag > , size : Size ) -> EvalResult < ' tcx > {
261
- let alloc = self . get ( ptr. alloc_id ) ?;
262
- alloc. undef_mask . is_range_defined (
247
+ self . undef_mask . is_range_defined (
263
248
ptr. offset ,
264
249
ptr. offset + size,
265
250
) . or_else ( |idx| err ! ( ReadUndefBytes ( idx) ) )
@@ -274,8 +259,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
274
259
if size. bytes ( ) == 0 {
275
260
return Ok ( ( ) ) ;
276
261
}
277
- let alloc = self . get_mut ( ptr. alloc_id ) ?;
278
- alloc. undef_mask . set_range (
262
+ self . undef_mask . set_range (
279
263
ptr. offset ,
280
264
ptr. offset + size,
281
265
new_state,
0 commit comments