Implement missing intrinsic

This commit is contained in:
Oliver Schneider 2018-05-07 18:02:57 +02:00
parent 0a88698daf
commit 6653bb38d5
No known key found for this signature in database
GPG Key ID: 1D5CB4FC597C3004

View File

@ -315,6 +315,20 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
self.write_primval(dest, result.0, dest_layout.ty)?;
}
"exact_div" => {
// Performs an exact division, resulting in undefined behavior where
// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
let ty = substs.type_at(0);
let a = self.value_to_primval(args[0])?;
let b = self.value_to_primval(args[1])?;
// check x % y != 0
if self.binary_op(mir::BinOp::Rem, a, ty, b, ty)?.0 != PrimVal::Bytes(0) {
return err!(ValidationFailure(format!("exact_div: {:?} cannot be divided by {:?}", a, b)));
}
let result = self.binary_op(mir::BinOp::Div, a, ty, b, ty)?;
self.write_primval(dest, result.0, dest_layout.ty)?;
},
"likely" | "unlikely" | "forget" => {}
"init" => {