error on failed assumptions
This commit is contained in:
parent
c57233abca
commit
23eb8a5cf2
3 changed files with 18 additions and 2 deletions
|
|
@ -43,6 +43,7 @@ pub enum EvalError<'tcx> {
|
|||
CalledClosureAsFunction,
|
||||
VtableForArgumentlessMethod,
|
||||
ModifiedConstantMemory,
|
||||
AssumptionNotHeld,
|
||||
}
|
||||
|
||||
pub type EvalResult<'tcx, T> = Result<T, EvalError<'tcx>>;
|
||||
|
|
@ -97,6 +98,8 @@ impl<'tcx> Error for EvalError<'tcx> {
|
|||
"tried to call a vtable function without arguments",
|
||||
EvalError::ModifiedConstantMemory =>
|
||||
"tried to modify constant memory",
|
||||
EvalError::AssumptionNotHeld =>
|
||||
"`assume` argument was false"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -284,8 +284,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
"sub_with_overflow" => self.intrinsic_with_overflow(mir::BinOp::Sub, &args[0], &args[1], dest, dest_layout)?,
|
||||
"mul_with_overflow" => self.intrinsic_with_overflow(mir::BinOp::Mul, &args[0], &args[1], dest, dest_layout)?,
|
||||
|
||||
// FIXME: turn into an assertion to catch wrong `assume` that would cause UB in llvm
|
||||
"assume" => {}
|
||||
"assume" => {
|
||||
if !self.memory.read_bool(args_ptrs[0])? {
|
||||
return Err(EvalError::AssumptionNotHeld);
|
||||
}
|
||||
}
|
||||
|
||||
"copy_nonoverlapping" => {
|
||||
let elem_ty = substs.type_at(0);
|
||||
|
|
|
|||
10
tests/compile-fail/assume.rs
Normal file
10
tests/compile-fail/assume.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#![feature(core_intrinsics)]
|
||||
|
||||
fn main() {
|
||||
let x = 5;
|
||||
unsafe {
|
||||
std::intrinsics::assume(x < 10);
|
||||
std::intrinsics::assume(x > 1);
|
||||
std::intrinsics::assume(x > 42); //~ ERROR: `assume` argument was false
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue