]> git.lizzy.rs Git - rust.git/commitdiff
for now, just use NULL ptr for unsized locals
authorRalf Jung <post@ralfj.de>
Wed, 19 Sep 2018 07:40:30 +0000 (09:40 +0200)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Thu, 25 Oct 2018 14:48:15 +0000 (16:48 +0200)
src/librustc/mir/interpret/mod.rs
src/librustc_mir/interpret/place.rs

index 40a4b8b375a2027af768ba6d95ca6c9062802676..9ef123d2daf50d1c64b13959a09477ba8949ea02 100644 (file)
@@ -176,7 +176,7 @@ pub fn new_with_tag(alloc_id: AllocId, offset: Size, tag: Tag) -> Self {
         Pointer { alloc_id, offset, tag }
     }
 
-    pub fn wrapping_signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> Self {
+    pub fn wrapping_signed_offset(self, i: i64, cx: impl HasDataLayout) -> Self {
         Pointer::new_with_tag(
             self.alloc_id,
             Size::from_bytes(cx.data_layout().wrapping_signed_offset(self.offset.bytes(), i)),
@@ -184,12 +184,12 @@ pub fn wrapping_signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> Self {
         )
     }
 
-    pub fn overflowing_signed_offset<C: HasDataLayout>(self, i: i128, cx: C) -> (Self, bool) {
+    pub fn overflowing_signed_offset(self, i: i128, cx: impl HasDataLayout) -> (Self, bool) {
         let (res, over) = cx.data_layout().overflowing_signed_offset(self.offset.bytes(), i);
         (Pointer::new_with_tag(self.alloc_id, Size::from_bytes(res), self.tag), over)
     }
 
-    pub fn signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> EvalResult<'tcx, Self> {
+    pub fn signed_offset(self, i: i64, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> {
         Ok(Pointer::new_with_tag(
             self.alloc_id,
             Size::from_bytes(cx.data_layout().signed_offset(self.offset.bytes(), i)?),
@@ -197,12 +197,12 @@ pub fn signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> EvalResult<'tcx,
         ))
     }
 
-    pub fn overflowing_offset<C: HasDataLayout>(self, i: Size, cx: C) -> (Self, bool) {
+    pub fn overflowing_offset(self, i: Size, cx: impl HasDataLayout) -> (Self, bool) {
         let (res, over) = cx.data_layout().overflowing_offset(self.offset.bytes(), i.bytes());
         (Pointer::new_with_tag(self.alloc_id, Size::from_bytes(res), self.tag), over)
     }
 
-    pub fn offset<C: HasDataLayout>(self, i: Size, cx: C) -> EvalResult<'tcx, Self> {
+    pub fn offset(self, i: Size, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> {
         Ok(Pointer::new_with_tag(
             self.alloc_id,
             Size::from_bytes(cx.data_layout().offset(self.offset.bytes(), i.bytes())?),
index b7bc4867307fb2b0aafe1eed27eed631da3c786a..4fa08e8c3111b4ffaa57bb5b2312b965954275f0 100644 (file)
@@ -125,6 +125,12 @@ pub fn from_scalar_ptr(ptr: Scalar<Tag>, align: Align) -> Self {
         }
     }
 
+    /// Produces a Place that will error if attempted to be read from or written to
+    #[inline(always)]
+    pub fn null(cx: impl HasDataLayout) -> Self {
+        Self::from_scalar_ptr(Scalar::ptr_null(cx), Align::from_bytes(1, 1).unwrap())
+    }
+
     #[inline(always)]
     pub fn from_ptr(ptr: Pointer<Tag>, align: Align) -> Self {
         Self::from_scalar_ptr(ptr.into(), align)
@@ -209,17 +215,17 @@ pub fn to_mem_place(self) -> MPlaceTy<'tcx, Tag> {
 
 impl<'tcx, Tag: ::std::fmt::Debug> Place<Tag> {
     /// Produces a Place that will error if attempted to be read from or written to
-    #[inline]
+    #[inline(always)]
     pub fn null(cx: impl HasDataLayout) -> Self {
-        Self::from_scalar_ptr(Scalar::ptr_null(cx), Align::from_bytes(1, 1).unwrap())
+        Place::Ptr(MemPlace::null(cx))
     }
 
-    #[inline]
+    #[inline(always)]
     pub fn from_scalar_ptr(ptr: Scalar<Tag>, align: Align) -> Self {
         Place::Ptr(MemPlace::from_scalar_ptr(ptr, align))
     }
 
-    #[inline]
+    #[inline(always)]
     pub fn from_ptr(ptr: Pointer<Tag>, align: Align) -> Self {
         Place::Ptr(MemPlace::from_ptr(ptr, align))
     }
@@ -882,10 +888,8 @@ pub fn allocate(
     ) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
         if layout.is_unsized() {
             assert!(self.tcx.features().unsized_locals, "cannot alloc memory for unsized type");
-            // allocate a fat pointer slot instead
-            let fat = self.tcx.mk_mut_ptr(layout.ty);
-            let fat = self.layout_of(fat)?;
-            self.allocate(fat, kind)
+            // FIXME: What should we do here?
+            Ok(MPlaceTy::dangling(layout, &self))
         } else {
             let ptr = self.memory.allocate(layout.size, layout.align, kind)?;
             Ok(MPlaceTy::from_aligned_ptr(ptr, layout))