]> git.lizzy.rs Git - rust.git/commitdiff
do not consider memory allocated by caller_location leaked
authorRalf Jung <post@ralfj.de>
Thu, 28 Nov 2019 18:15:32 +0000 (19:15 +0100)
committerRalf Jung <post@ralfj.de>
Thu, 28 Nov 2019 18:15:32 +0000 (19:15 +0100)
src/librustc_mir/interpret/intern.rs
src/librustc_mir/interpret/intrinsics/caller_location.rs
src/librustc_mir/interpret/memory.rs

index 630f3f603449bb0fccd84250324ac0a39a934bc4..f9cb40ffe9446eac23b7bd967283ab11a29a130f 100644 (file)
@@ -100,7 +100,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
     // This match is just a canary for future changes to `MemoryKind`, which most likely need
     // changes in this function.
     match kind {
-        MemoryKind::Stack | MemoryKind::Vtable => {},
+        MemoryKind::Stack | MemoryKind::Vtable | MemoryKind::CallerLocation => {},
     }
     // Set allocation mutability as appropriate. This is used by LLVM to put things into
     // read-only memory, and also by Miri when evluating other constants/statics that
index 88bfcd63129fa9759fa27e9bab358e109438cc23..9e07a3f1072c1c5d18a8bf4702b9fe997758d79f 100644 (file)
@@ -28,7 +28,7 @@ pub fn alloc_caller_location(
         let file = Scalar::Ptr(self.tag_static_base_pointer(file_ptr));
         let file_len = Scalar::from_uint(filename.as_str().len() as u128, ptr_size);
 
-        let location = self.allocate(loc_layout, MemoryKind::Stack);
+        let location = self.allocate(loc_layout, MemoryKind::CallerLocation);
 
         let file_out = self.mplace_field(location, 0)?;
         let file_ptr_out = self.force_ptr(self.mplace_field(file_out, 0)?.ptr)?;
index eccdc5b03261b8dbbe8f47ba040d1b434e2cb09c..a8011f7abb14fe41e6699b0e6499f4091c6cad6c 100644 (file)
 
 #[derive(Debug, PartialEq, Copy, Clone)]
 pub enum MemoryKind<T> {
-    /// Error if deallocated except during a stack pop
+    /// Stack memory. Error if deallocated except during a stack pop.
     Stack,
-    /// Error if ever deallocated
+    /// Memory backing vtables. Error if ever deallocated.
     Vtable,
-    /// Additional memory kinds a machine wishes to distinguish from the builtin ones
+    /// Memory allocated by `caller_location` intrinsic. Error if ever deallocated.
+    CallerLocation,
+    /// Additional memory kinds a machine wishes to distinguish from the builtin ones.
     Machine(T),
 }
 
@@ -38,6 +40,7 @@ fn may_leak(self) -> bool {
         match self {
             MemoryKind::Stack => false,
             MemoryKind::Vtable => true,
+            MemoryKind::CallerLocation => true,
             MemoryKind::Machine(k) => k.may_leak()
         }
     }
@@ -719,6 +722,7 @@ pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
                     let extra = match kind {
                         MemoryKind::Stack => " (stack)".to_owned(),
                         MemoryKind::Vtable => " (vtable)".to_owned(),
+                        MemoryKind::CallerLocation => " (caller_location)".to_owned(),
                         MemoryKind::Machine(m) => format!(" ({:?})", m),
                     };
                     self.dump_alloc_helper(