Skip to content

Commit b81302f

Browse files
RalfJungoli-obk
authored andcommitted
for now, just use NULL ptr for unsized locals
1 parent 7717a63 commit b81302f

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/librustc/mir/interpret/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,33 +176,33 @@ impl<'tcx, Tag> Pointer<Tag> {
176176
Pointer { alloc_id, offset, tag }
177177
}
178178

179-
pub fn wrapping_signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> Self {
179+
pub fn wrapping_signed_offset(self, i: i64, cx: impl HasDataLayout) -> Self {
180180
Pointer::new_with_tag(
181181
self.alloc_id,
182182
Size::from_bytes(cx.data_layout().wrapping_signed_offset(self.offset.bytes(), i)),
183183
self.tag,
184184
)
185185
}
186186

187-
pub fn overflowing_signed_offset<C: HasDataLayout>(self, i: i128, cx: C) -> (Self, bool) {
187+
pub fn overflowing_signed_offset(self, i: i128, cx: impl HasDataLayout) -> (Self, bool) {
188188
let (res, over) = cx.data_layout().overflowing_signed_offset(self.offset.bytes(), i);
189189
(Pointer::new_with_tag(self.alloc_id, Size::from_bytes(res), self.tag), over)
190190
}
191191

192-
pub fn signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> EvalResult<'tcx, Self> {
192+
pub fn signed_offset(self, i: i64, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> {
193193
Ok(Pointer::new_with_tag(
194194
self.alloc_id,
195195
Size::from_bytes(cx.data_layout().signed_offset(self.offset.bytes(), i)?),
196196
self.tag,
197197
))
198198
}
199199

200-
pub fn overflowing_offset<C: HasDataLayout>(self, i: Size, cx: C) -> (Self, bool) {
200+
pub fn overflowing_offset(self, i: Size, cx: impl HasDataLayout) -> (Self, bool) {
201201
let (res, over) = cx.data_layout().overflowing_offset(self.offset.bytes(), i.bytes());
202202
(Pointer::new_with_tag(self.alloc_id, Size::from_bytes(res), self.tag), over)
203203
}
204204

205-
pub fn offset<C: HasDataLayout>(self, i: Size, cx: C) -> EvalResult<'tcx, Self> {
205+
pub fn offset(self, i: Size, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> {
206206
Ok(Pointer::new_with_tag(
207207
self.alloc_id,
208208
Size::from_bytes(cx.data_layout().offset(self.offset.bytes(), i.bytes())?),

src/librustc_mir/interpret/place.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ impl<Tag> MemPlace<Tag> {
125125
}
126126
}
127127

128+
/// Produces a Place that will error if attempted to be read from or written to
129+
#[inline(always)]
130+
pub fn null(cx: impl HasDataLayout) -> Self {
131+
Self::from_scalar_ptr(Scalar::ptr_null(cx), Align::from_bytes(1, 1).unwrap())
132+
}
133+
128134
#[inline(always)]
129135
pub fn from_ptr(ptr: Pointer<Tag>, align: Align) -> Self {
130136
Self::from_scalar_ptr(ptr.into(), align)
@@ -209,17 +215,17 @@ impl<'tcx, Tag: ::std::fmt::Debug> OpTy<'tcx, Tag> {
209215

210216
impl<'tcx, Tag: ::std::fmt::Debug> Place<Tag> {
211217
/// Produces a Place that will error if attempted to be read from or written to
212-
#[inline]
218+
#[inline(always)]
213219
pub fn null(cx: impl HasDataLayout) -> Self {
214-
Self::from_scalar_ptr(Scalar::ptr_null(cx), Align::from_bytes(1, 1).unwrap())
220+
Place::Ptr(MemPlace::null(cx))
215221
}
216222

217-
#[inline]
223+
#[inline(always)]
218224
pub fn from_scalar_ptr(ptr: Scalar<Tag>, align: Align) -> Self {
219225
Place::Ptr(MemPlace::from_scalar_ptr(ptr, align))
220226
}
221227

222-
#[inline]
228+
#[inline(always)]
223229
pub fn from_ptr(ptr: Pointer<Tag>, align: Align) -> Self {
224230
Place::Ptr(MemPlace::from_ptr(ptr, align))
225231
}
@@ -882,10 +888,8 @@ where
882888
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
883889
if layout.is_unsized() {
884890
assert!(self.tcx.features().unsized_locals, "cannot alloc memory for unsized type");
885-
// allocate a fat pointer slot instead
886-
let fat = self.tcx.mk_mut_ptr(layout.ty);
887-
let fat = self.layout_of(fat)?;
888-
self.allocate(fat, kind)
891+
// FIXME: What should we do here?
892+
Ok(MPlaceTy::dangling(layout, &self))
889893
} else {
890894
let ptr = self.memory.allocate(layout.size, layout.align, kind)?;
891895
Ok(MPlaceTy::from_aligned_ptr(ptr, layout))

0 commit comments

Comments
 (0)