Skip to content

Commit 04210f3

Browse files
committed
Access self instead of alloc
1 parent c392fbb commit 04210f3

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,12 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
6060
pub fn check_bounds_ptr(
6161
&self,
6262
ptr: Pointer<Tag>,
63-
check: InboundsCheck,
6463
) -> 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;
7465
if ptr.offset.bytes() > allocation_size {
7566
return err!(PointerOutOfBounds {
7667
ptr: ptr.erase_tag(),
77-
check,
68+
check: InboundsCheck::Live,
7869
allocation_size: Size::from_bytes(allocation_size),
7970
});
8071
}
@@ -87,15 +78,14 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
8778
&self,
8879
ptr: Pointer<Tag>,
8980
size: Size,
90-
check: InboundsCheck,
9181
) -> EvalResult<'tcx> {
9282
// 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)?)
9484
}
9585
}
9686

9787
/// Byte accessors
98-
impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
88+
impl<'tcx, Tag, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
9989
/// The last argument controls whether we error out when there are undefined
10090
/// or pointer bytes. You should never call this, call `get_bytes` or
10191
/// `get_bytes_with_undef_and_ptr` instead,
@@ -122,13 +112,12 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
122112
self.check_relocation_edges(ptr, size)?;
123113
}
124114

125-
let alloc = self.get(ptr.alloc_id)?;
126-
AllocationExtra::memory_read(alloc, ptr, size)?;
115+
AllocationExtra::memory_read(self, ptr, size)?;
127116

128117
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
129118
assert_eq!(size.bytes() as usize as u64, size.bytes());
130119
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])
132121
}
133122

134123
#[inline]
@@ -168,13 +157,12 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
168157
self.mark_definedness(ptr, size, true)?;
169158
self.clear_relocations(ptr, size)?;
170159

171-
let alloc = self.get_mut(ptr.alloc_id)?;
172-
AllocationExtra::memory_written(alloc, ptr, size)?;
160+
AllocationExtra::memory_written(self, ptr, size)?;
173161

174162
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
175163
assert_eq!(size.bytes() as usize as u64, size.bytes());
176164
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])
178166
}
179167
}
180168

@@ -190,7 +178,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
190178
// the beginning of this range.
191179
let start = ptr.offset.bytes().saturating_sub(self.pointer_size().bytes() - 1);
192180
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))
194182
}
195183

196184
/// Check that there ar eno relocations overlapping with the given range.
@@ -224,19 +212,17 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
224212
let start = ptr.offset;
225213
let end = start + size;
226214

227-
let alloc = self.get_mut(ptr.alloc_id)?;
228-
229215
// Mark parts of the outermost relocations as undefined if they partially fall outside the
230216
// given range.
231217
if first < start {
232-
alloc.undef_mask.set_range(first, start, false);
218+
self.undef_mask.set_range(first, start, false);
233219
}
234220
if last > end {
235-
alloc.undef_mask.set_range(end, last, false);
221+
self.undef_mask.set_range(end, last, false);
236222
}
237223

238224
// Forget all the relocations.
239-
alloc.relocations.remove_range(first..last);
225+
self.relocations.remove_range(first..last);
240226

241227
Ok(())
242228
}
@@ -258,8 +244,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
258244
/// error which will report the first byte which is undefined.
259245
#[inline]
260246
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(
263248
ptr.offset,
264249
ptr.offset + size,
265250
).or_else(|idx| err!(ReadUndefBytes(idx)))
@@ -274,8 +259,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
274259
if size.bytes() == 0 {
275260
return Ok(());
276261
}
277-
let alloc = self.get_mut(ptr.alloc_id)?;
278-
alloc.undef_mask.set_range(
262+
self.undef_mask.set_range(
279263
ptr.offset,
280264
ptr.offset + size,
281265
new_state,

0 commit comments

Comments
 (0)