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

Alloc api fix and tmp disable validation_op because of ICE #373

Merged
merged 4 commits into from
May 7, 2018
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
23 changes: 9 additions & 14 deletions miri/fn_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use rustc::ty::{self, Ty};
use rustc::ty::layout::{self, Align, LayoutOf};
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
use rustc::mir;
use rustc_target::spec::abi::Abi;
use rustc_data_structures::indexed_vec::Idx;
use syntax::attr;
use syntax::codemap::Span;
Expand Down Expand Up @@ -627,7 +626,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '

match &path[..] {
// Allocators are magic. They have no MIR, even when the rest of libstd does.
"alloc::heap::::__rust_alloc" => {
"alloc::alloc::::__rust_alloc" => {
let size = self.value_to_primval(args[0])?.to_u64()?;
let align = self.value_to_primval(args[1])?.to_u64()?;
if size == 0 {
Expand All @@ -641,7 +640,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
Some(MemoryKind::Rust.into()))?;
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
}
"alloc::heap::::__rust_alloc_zeroed" => {
"alloc::alloc::::__rust_alloc_zeroed" => {
let size = self.value_to_primval(args[0])?.to_u64()?;
let align = self.value_to_primval(args[1])?.to_u64()?;
if size == 0 {
Expand All @@ -656,7 +655,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
self.memory.write_repeat(ptr.into(), 0, size)?;
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
}
"alloc::heap::::__rust_dealloc" => {
"alloc::alloc::::__rust_dealloc" => {
let ptr = self.into_ptr(args[0].value)?.to_ptr()?;
let old_size = self.value_to_primval(args[1])?.to_u64()?;
let align = self.value_to_primval(args[2])?.to_u64()?;
Expand All @@ -672,27 +671,23 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
MemoryKind::Rust.into(),
)?;
}
"alloc::heap::::__rust_realloc" => {
"alloc::alloc::::__rust_realloc" => {
let ptr = self.into_ptr(args[0].value)?.to_ptr()?;
let old_size = self.value_to_primval(args[1])?.to_u64()?;
let old_align = self.value_to_primval(args[2])?.to_u64()?;
let align = self.value_to_primval(args[2])?.to_u64()?;
let new_size = self.value_to_primval(args[3])?.to_u64()?;
let new_align = self.value_to_primval(args[4])?.to_u64()?;
if old_size == 0 || new_size == 0 {
return err!(HeapAllocZeroBytes);
}
if !old_align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(old_align));
}
if !new_align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(new_align));
if !align.is_power_of_two() {
return err!(HeapAllocNonPowerOfTwoAlignment(align));
}
let new_ptr = self.memory.reallocate(
ptr,
old_size,
Align::from_bytes(old_align, old_align).unwrap(),
Align::from_bytes(align, align).unwrap(),
new_size,
Align::from_bytes(new_align, new_align).unwrap(),
Align::from_bytes(align, align).unwrap(),
MemoryKind::Rust.into(),
)?;
self.write_primval(dest, PrimVal::Ptr(new_ptr), dest_ty)?;
Expand Down
6 changes: 4 additions & 2 deletions miri/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ extern crate log;
// From rustc.
#[macro_use]
extern crate rustc;
extern crate rustc_data_structures;
extern crate rustc_mir;
extern crate rustc_target;
extern crate rustc_data_structures;
extern crate syntax;
extern crate regex;
#[macro_use]
Expand Down Expand Up @@ -448,6 +448,8 @@ impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
op: ::rustc::mir::ValidationOp,
operand: &::rustc::mir::ValidationOperand<'tcx, ::rustc::mir::Place<'tcx>>,
) -> EvalResult<'tcx> {
ecx.validation_op(op, operand)
// FIXME: prevent this from ICEing
//ecx.validation_op(op, operand)
Ok(())
}
}