Skip to content

Commit 3048d7e

Browse files
committed
do not consider memory allocated by caller_location leaked
1 parent 04e69e4 commit 3048d7e

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Diff for: src/librustc_mir/interpret/intern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
100100
// This match is just a canary for future changes to `MemoryKind`, which most likely need
101101
// changes in this function.
102102
match kind {
103-
MemoryKind::Stack | MemoryKind::Vtable => {},
103+
MemoryKind::Stack | MemoryKind::Vtable | MemoryKind::CallerLocation => {},
104104
}
105105
// Set allocation mutability as appropriate. This is used by LLVM to put things into
106106
// read-only memory, and also by Miri when evluating other constants/statics that

Diff for: src/librustc_mir/interpret/intrinsics/caller_location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2828
let file = Scalar::Ptr(self.tag_static_base_pointer(file_ptr));
2929
let file_len = Scalar::from_uint(filename.as_str().len() as u128, ptr_size);
3030

31-
let location = self.allocate(loc_layout, MemoryKind::Stack);
31+
let location = self.allocate(loc_layout, MemoryKind::CallerLocation);
3232

3333
let file_out = self.mplace_field(location, 0)?;
3434
let file_ptr_out = self.force_ptr(self.mplace_field(file_out, 0)?.ptr)?;

Diff for: src/librustc_mir/interpret/memory.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ use super::{
2424

2525
#[derive(Debug, PartialEq, Copy, Clone)]
2626
pub enum MemoryKind<T> {
27-
/// Error if deallocated except during a stack pop
27+
/// Stack memory. Error if deallocated except during a stack pop.
2828
Stack,
29-
/// Error if ever deallocated
29+
/// Memory backing vtables. Error if ever deallocated.
3030
Vtable,
31-
/// Additional memory kinds a machine wishes to distinguish from the builtin ones
31+
/// Memory allocated by `caller_location` intrinsic. Error if ever deallocated.
32+
CallerLocation,
33+
/// Additional memory kinds a machine wishes to distinguish from the builtin ones.
3234
Machine(T),
3335
}
3436

@@ -38,6 +40,7 @@ impl<T: MayLeak> MayLeak for MemoryKind<T> {
3840
match self {
3941
MemoryKind::Stack => false,
4042
MemoryKind::Vtable => true,
43+
MemoryKind::CallerLocation => true,
4144
MemoryKind::Machine(k) => k.may_leak()
4245
}
4346
}
@@ -719,6 +722,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
719722
let extra = match kind {
720723
MemoryKind::Stack => " (stack)".to_owned(),
721724
MemoryKind::Vtable => " (vtable)".to_owned(),
725+
MemoryKind::CallerLocation => " (caller_location)".to_owned(),
722726
MemoryKind::Machine(m) => format!(" ({:?})", m),
723727
};
724728
self.dump_alloc_helper(

0 commit comments

Comments
 (0)