Add unstably const support for assume intrinsic
This commit is contained in:
parent
3e08354fb0
commit
4387480dea
3 changed files with 24 additions and 0 deletions
|
@ -435,6 +435,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
// These just return their argument
|
// These just return their argument
|
||||||
self.copy_op(args[0], dest)?;
|
self.copy_op(args[0], dest)?;
|
||||||
}
|
}
|
||||||
|
sym::assume => {
|
||||||
|
let cond = self.read_scalar(args[0])?.check_init()?.to_bool()?;
|
||||||
|
if !cond {
|
||||||
|
throw_ub_format!("`assume` intrinsic called with `false`");
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => return Ok(false),
|
_ => return Ok(false),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -733,6 +733,7 @@ extern "rust-intrinsic" {
|
||||||
/// own, or if it does not enable any significant optimizations.
|
/// own, or if it does not enable any significant optimizations.
|
||||||
///
|
///
|
||||||
/// This intrinsic does not have a stable counterpart.
|
/// This intrinsic does not have a stable counterpart.
|
||||||
|
#[rustc_const_unstable(feature = "const_assume", issue = "76972")]
|
||||||
pub fn assume(b: bool);
|
pub fn assume(b: bool);
|
||||||
|
|
||||||
/// Hints to the compiler that branch condition is likely to be true.
|
/// Hints to the compiler that branch condition is likely to be true.
|
||||||
|
|
17
src/test/ui/consts/const-eval/const_assume.rs
Normal file
17
src/test/ui/consts/const-eval/const_assume.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
// Check that `const_assume` feature allow `assume` intrinsic
|
||||||
|
// to be used in const contexts.
|
||||||
|
|
||||||
|
#![feature(core_intrinsics, const_assume)]
|
||||||
|
|
||||||
|
extern crate core;
|
||||||
|
|
||||||
|
use core::intrinsics::assume;
|
||||||
|
|
||||||
|
pub const unsafe fn foo(x: usize, y: usize) -> usize {
|
||||||
|
assume(y != 0);
|
||||||
|
x / y
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue