mirror of https://github.com/rust-lang/rust.git
Make ptr_guaranteed_cmp a rustc_intrinsic and favor its body over backends implementing it
This commit is contained in:
parent
e0d67aeb0b
commit
3e5c468662
|
@ -757,13 +757,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
|||
ret.write_cvalue(fx, val);
|
||||
}
|
||||
|
||||
sym::ptr_guaranteed_cmp => {
|
||||
intrinsic_args!(fx, args => (a, b); intrinsic);
|
||||
|
||||
let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b).load_scalar(fx);
|
||||
ret.write_cvalue(fx, CValue::by_val(val, fx.layout_of(fx.tcx.types.u8)));
|
||||
}
|
||||
|
||||
sym::caller_location => {
|
||||
intrinsic_args!(fx, args => (); intrinsic);
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use super::operand::{OperandRef, OperandValue};
|
||||
use super::place::PlaceRef;
|
||||
use super::FunctionCx;
|
||||
use crate::common::IntPredicate;
|
||||
use crate::errors;
|
||||
use crate::errors::InvalidMonomorphization;
|
||||
use crate::meth;
|
||||
|
@ -456,12 +455,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
sym::ptr_guaranteed_cmp => {
|
||||
let a = args[0].immediate();
|
||||
let b = args[1].immediate();
|
||||
bx.icmp(IntPredicate::IntEQ, a, b)
|
||||
}
|
||||
|
||||
sym::ptr_offset_from | sym::ptr_offset_from_unsigned => {
|
||||
let ty = fn_args.type_at(0);
|
||||
let pointee_size = bx.layout_of(ty).size;
|
||||
|
|
|
@ -441,7 +441,7 @@ pub fn check_intrinsic_type(
|
|||
|
||||
sym::ptr_guaranteed_cmp => (
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
|
||||
tcx.types.u8,
|
||||
),
|
||||
|
|
|
@ -2434,20 +2434,29 @@ extern "rust-intrinsic" {
|
|||
#[rustc_nounwind]
|
||||
pub fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
|
||||
|
||||
/// See documentation of `<*const T>::guaranteed_eq` for details.
|
||||
/// Returns `2` if the result is unknown.
|
||||
/// Returns `1` if the pointers are guaranteed equal
|
||||
/// Returns `0` if the pointers are guaranteed inequal
|
||||
///
|
||||
/// Note that, unlike most intrinsics, this is safe to call;
|
||||
/// it does not require an `unsafe` block.
|
||||
/// Therefore, implementations must not require the user to uphold
|
||||
/// any safety invariants.
|
||||
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
|
||||
#[rustc_safe_intrinsic]
|
||||
#[rustc_nounwind]
|
||||
#[cfg(bootstrap)]
|
||||
pub fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8;
|
||||
}
|
||||
|
||||
/// See documentation of `<*const T>::guaranteed_eq` for details.
|
||||
/// Returns `2` if the result is unknown.
|
||||
/// Returns `1` if the pointers are guaranteed equal
|
||||
/// Returns `0` if the pointers are guaranteed inequal
|
||||
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
|
||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||
#[rustc_intrinsic]
|
||||
#[cfg(not(bootstrap))]
|
||||
#[rustc_nounwind]
|
||||
#[rustc_do_not_const_check]
|
||||
#[inline]
|
||||
pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 {
|
||||
(ptr == other) as u8
|
||||
}
|
||||
|
||||
extern "rust-intrinsic" {
|
||||
/// Determines whether the raw bytes of the two values are equal.
|
||||
///
|
||||
/// This is particularly handy for arrays, since it allows things like just
|
||||
|
|
Loading…
Reference in New Issue