From 271faf05b8e59bcb75cb67ed6d89194cf831e2ed Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Sun, 11 Nov 2018 13:22:53 +0100 Subject: [PATCH] do not validate the argument to the __breakpoint intrinsic --- library/stdarch/coresimd/arm/armclang.rs | 37 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/library/stdarch/coresimd/arm/armclang.rs b/library/stdarch/coresimd/arm/armclang.rs index 233fe9d6fc4e..39bbe3f1506f 100644 --- a/library/stdarch/coresimd/arm/armclang.rs +++ b/library/stdarch/coresimd/arm/armclang.rs @@ -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); }