Skip to content

Commit 1dcda69

Browse files
committed
Auto merge of #51225 - oli-obk:miri_oob_ptr, r=eddyb
Fix the miri submodule cc @bjorn3 r? @eddyb
2 parents 63cd4a3 + 0639451 commit 1dcda69

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

src/librustc_mir/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
793793
let ty = self.place_ty(place);
794794
let place = self.eval_place(place)?;
795795
let discr_val = self.read_discriminant_value(place, ty)?;
796-
let defined = self.layout_of(ty).unwrap().size.bits() as u8;
796+
let defined = self.layout_of(dest_ty).unwrap().size.bits() as u8;
797797
self.write_scalar(dest, Scalar::Bits {
798798
bits: discr_val,
799799
defined,

src/librustc_mir/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
844844
}
845845

846846
// Forget all the relocations.
847-
alloc.relocations.remove_range(first ..= last);
847+
alloc.relocations.remove_range(first..last);
848848

849849
Ok(())
850850
}

src/librustc_mir/interpret/terminator/mod.rs

+28-13
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
3939
} => {
4040
let discr_val = self.eval_operand(discr)?;
4141
let discr_prim = self.value_to_scalar(discr_val)?;
42+
let discr_layout = self.layout_of(discr_val.ty).unwrap();
43+
trace!("SwitchInt({:?}, {:#?})", discr_prim, discr_layout);
44+
let discr_prim = discr_prim.to_bits(discr_layout.size)?;
4245

4346
// Branch to the `otherwise` case by default, if no match is found.
4447
let mut target_block = targets[targets.len() - 1];
4548

4649
for (index, &const_int) in values.iter().enumerate() {
47-
if discr_prim.to_bits(self.layout_of(discr_val.ty).unwrap().size)? == const_int {
50+
if discr_prim == const_int {
4851
target_block = targets[index];
4952
break;
5053
}
@@ -288,10 +291,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
288291
// and need to pack arguments
289292
Abi::Rust => {
290293
trace!(
291-
"arg_locals: {:?}",
294+
"arg_locals: {:#?}",
292295
self.frame().mir.args_iter().collect::<Vec<_>>()
293296
);
294-
trace!("args: {:?}", args);
297+
trace!("args: {:#?}", args);
295298
let local = arg_locals.nth(1).unwrap();
296299
for (i, &valty) in args.into_iter().enumerate() {
297300
let dest = self.eval_place(&mir::Place::Local(local).field(
@@ -318,10 +321,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
318321
let mut arg_locals = self.frame().mir.args_iter();
319322
trace!("ABI: {:?}", sig.abi);
320323
trace!(
321-
"arg_locals: {:?}",
324+
"arg_locals: {:#?}",
322325
self.frame().mir.args_iter().collect::<Vec<_>>()
323326
);
324-
trace!("args: {:?}", args);
327+
trace!("args: {:#?}", args);
325328
match sig.abi {
326329
Abi::RustCall => {
327330
assert_eq!(args.len(), 2);
@@ -373,14 +376,26 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
373376
}
374377
break;
375378
}
376-
let dest = self.eval_place(&mir::Place::Local(
377-
arg_locals.next().unwrap(),
378-
))?;
379-
let valty = ValTy {
380-
value: other,
381-
ty: layout.ty,
382-
};
383-
self.write_value(valty, dest)?;
379+
{
380+
let mut write_next = |value| {
381+
let dest = self.eval_place(&mir::Place::Local(
382+
arg_locals.next().unwrap(),
383+
))?;
384+
let valty = ValTy {
385+
value: Value::Scalar(value),
386+
ty: layout.ty,
387+
};
388+
self.write_value(valty, dest)
389+
};
390+
match other {
391+
Value::Scalar(value) | Value::ScalarPair(value, _) => write_next(value)?,
392+
_ => unreachable!(),
393+
}
394+
if let Value::ScalarPair(_, value) = other {
395+
write_next(value)?;
396+
}
397+
}
398+
assert!(arg_locals.next().is_none());
384399
}
385400
}
386401
} else {

src/tools/miri

Submodule miri updated from 6a4c62c to 066a284

0 commit comments

Comments
 (0)