Skip to content

Commit 3ffc237

Browse files
authored
Merge pull request #373 from bjorn3/alloc_fix
Alloc api fix and tmp disable validation_op because of ICE
2 parents 696dda8 + 42ab135 commit 3ffc237

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

miri/fn_call.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
626626

627627
match &path[..] {
628628
// Allocators are magic. They have no MIR, even when the rest of libstd does.
629-
"alloc::heap::::__rust_alloc" => {
629+
"alloc::alloc::::__rust_alloc" => {
630630
let size = self.value_to_primval(args[0])?.to_u64()?;
631631
let align = self.value_to_primval(args[1])?.to_u64()?;
632632
if size == 0 {
@@ -640,7 +640,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
640640
Some(MemoryKind::Rust.into()))?;
641641
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
642642
}
643-
"alloc::heap::::__rust_alloc_zeroed" => {
643+
"alloc::alloc::::__rust_alloc_zeroed" => {
644644
let size = self.value_to_primval(args[0])?.to_u64()?;
645645
let align = self.value_to_primval(args[1])?.to_u64()?;
646646
if size == 0 {
@@ -655,7 +655,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
655655
self.memory.write_repeat(ptr.into(), 0, size)?;
656656
self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?;
657657
}
658-
"alloc::heap::::__rust_dealloc" => {
658+
"alloc::alloc::::__rust_dealloc" => {
659659
let ptr = self.into_ptr(args[0].value)?.to_ptr()?;
660660
let old_size = self.value_to_primval(args[1])?.to_u64()?;
661661
let align = self.value_to_primval(args[2])?.to_u64()?;
@@ -671,27 +671,23 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx> for EvalContext<'a, 'mir, '
671671
MemoryKind::Rust.into(),
672672
)?;
673673
}
674-
"alloc::heap::::__rust_realloc" => {
674+
"alloc::alloc::::__rust_realloc" => {
675675
let ptr = self.into_ptr(args[0].value)?.to_ptr()?;
676676
let old_size = self.value_to_primval(args[1])?.to_u64()?;
677-
let old_align = self.value_to_primval(args[2])?.to_u64()?;
677+
let align = self.value_to_primval(args[2])?.to_u64()?;
678678
let new_size = self.value_to_primval(args[3])?.to_u64()?;
679-
let new_align = self.value_to_primval(args[4])?.to_u64()?;
680679
if old_size == 0 || new_size == 0 {
681680
return err!(HeapAllocZeroBytes);
682681
}
683-
if !old_align.is_power_of_two() {
684-
return err!(HeapAllocNonPowerOfTwoAlignment(old_align));
685-
}
686-
if !new_align.is_power_of_two() {
687-
return err!(HeapAllocNonPowerOfTwoAlignment(new_align));
682+
if !align.is_power_of_two() {
683+
return err!(HeapAllocNonPowerOfTwoAlignment(align));
688684
}
689685
let new_ptr = self.memory.reallocate(
690686
ptr,
691687
old_size,
692-
Align::from_bytes(old_align, old_align).unwrap(),
688+
Align::from_bytes(align, align).unwrap(),
693689
new_size,
694-
Align::from_bytes(new_align, new_align).unwrap(),
690+
Align::from_bytes(align, align).unwrap(),
695691
MemoryKind::Rust.into(),
696692
)?;
697693
self.write_primval(dest, PrimVal::Ptr(new_ptr), dest_ty)?;

miri/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ impl<'mir, 'tcx: 'mir> Machine<'mir, 'tcx> for Evaluator<'tcx> {
448448
op: ::rustc::mir::ValidationOp,
449449
operand: &::rustc::mir::ValidationOperand<'tcx, ::rustc::mir::Place<'tcx>>,
450450
) -> EvalResult<'tcx> {
451-
ecx.validation_op(op, operand)
451+
// FIXME: prevent this from ICEing
452+
//ecx.validation_op(op, operand)
453+
Ok(())
452454
}
453455
}

0 commit comments

Comments
 (0)