Lower the assume intrinsic to a MIR statement
This commit is contained in:
parent
3c72788461
commit
3f07645120
33 changed files with 212 additions and 30 deletions
|
@ -506,12 +506,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// These just return their argument
|
||||
self.copy_op(&args[0], dest, /*allow_transmute*/ false)?;
|
||||
}
|
||||
sym::assume => {
|
||||
let cond = self.read_scalar(&args[0])?.to_bool()?;
|
||||
if !cond {
|
||||
throw_ub_format!("`assume` intrinsic called with `false`");
|
||||
}
|
||||
}
|
||||
sym::raw_eq => {
|
||||
let result = self.raw_eq_intrinsic(&args[0], &args[1])?;
|
||||
self.write_scalar(result, dest)?;
|
||||
|
|
|
@ -122,6 +122,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
self.copy_intrinsic(&src, &dst, &count, /* nonoverlapping */ true)?;
|
||||
}
|
||||
|
||||
// Call Assume
|
||||
Assume(box op) => {
|
||||
let op = self.eval_operand(op, None)?;
|
||||
let cond = self.read_scalar(&op)?.to_bool()?;
|
||||
if !cond {
|
||||
throw_ub_format!("`assume` called with `false`");
|
||||
}
|
||||
}
|
||||
|
||||
// Statements we do not track.
|
||||
AscribeUserType(..) => {}
|
||||
|
||||
|
|
|
@ -679,6 +679,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
|||
| StatementKind::AscribeUserType(..)
|
||||
| StatementKind::Coverage(..)
|
||||
| StatementKind::CopyNonOverlapping(..)
|
||||
| StatementKind::Assume(..)
|
||||
| StatementKind::Nop => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -636,6 +636,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
}
|
||||
StatementKind::Assume(box ref op) => {
|
||||
let ty = op.ty(&self.body.local_decls, self.tcx);
|
||||
if !ty.is_bool() {
|
||||
self.fail(
|
||||
location,
|
||||
format!("`assume` argument must be `bool`, but got: `{}`", ty),
|
||||
);
|
||||
}
|
||||
}
|
||||
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
|
||||
ref src,
|
||||
ref dst,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue