Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miri: do not consider memory allocated by caller_location leaked #66844

Merged
merged 1 commit into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/intrinsics/caller_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
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)?;
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ use super::{

#[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),
}

Expand All @@ -38,6 +40,7 @@ impl<T: MayLeak> MayLeak for MemoryKind<T> {
match self {
MemoryKind::Stack => false,
MemoryKind::Vtable => true,
MemoryKind::CallerLocation => true,
MemoryKind::Machine(k) => k.may_leak()
}
}
Expand Down Expand Up @@ -719,6 +722,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
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(
Expand Down