do not validate the argument to the __breakpoint intrinsic

This commit is contained in:
gnzlbg 2018-11-11 13:22:53 +01:00 committed by gnzlbg
parent 3bf788b48d
commit 271faf05b8

View file

@ -2,24 +2,38 @@
//!
//! # References
//!
//! - [ARM Compiler v 6.10 - armclang Reference Guide](https://developer.arm.com/docs/100067/0610)
//! - [ARM Compiler v 6.10 - armclang Reference Guide][arm_comp_ref]
//!
//! [arm_comp_ref]: https://developer.arm.com/docs/100067/0610
#[cfg(test)]
use stdsimd_test::assert_instr;
/// This intrinsic inserts a BKPT instruction into the instruction stream generated by the compiler
/// Inserts a breakpoint instruction.
///
/// It enables you to include a breakpoint instruction in your Rust code
/// `val` is a compile-time constant integer in range `[0, 255]`.
///
/// `val` is a compile-time constant integer whose range is:
/// The breakpoint instruction inserted is:
///
/// - `0...65535` if you are compiling source as A32 or A64 code.
/// - `0...255` if you are compiling source as T32 code.
/// * `BKPT` when compiling as T32,
/// * `BRK` when compiling as A32 or A64.
///
/// [ARM's documentation](https://developer.arm.com/docs/100067/latest/compiler-specific-intrinsics/__breakpoint-intrinsic)
/// # Safety
///
/// **NOTE**: Due to compiler limitations this function only supports the range `0...255` in A32 and
/// A64 mode.
/// If `val` is out-of-range the behavior is **undefined**.
///
/// # Note
///
/// [ARM's documentation][arm_docs] defines that `__breakpoint` accepts the
/// following values for `val`:
///
/// - `0...65535` when compiling as A32 or A64,
/// - `0...255` when compiling as T32.
///
/// The current implementation only accepts values in range `[0, 255]` - if the
/// value is out-of-range the behavior is **undefined**.
///
/// [arm_docs]: https://developer.arm.com/docs/100067/latest/compiler-specific-intrinsics/__breakpoint-intrinsic
#[cfg_attr(all(test, target_arch = "arm"), assert_instr(bkpt, val = 0))]
#[cfg_attr(all(test, target_arch = "aarch64"), assert_instr(brk, val = 0))]
#[inline(always)]
@ -39,8 +53,7 @@ pub unsafe fn __breakpoint(val: i32) {
}
}
// validate range
assert!(val >= 0 && val <= 255);
// We can't `panic!` inside this intrinsic, so we can't really validate the
// arguments here. If `val` is out-of-range this macro uses `val == 255`:
constify_imm8!(val, call);
}