Add a pointer to address cast kind
A pointer to address cast are often special-cased. Introduce a dedicated cast kind to make them easy distinguishable.
This commit is contained in:
parent
d35d972e69
commit
dff602fc18
15 changed files with 96 additions and 94 deletions
|
@ -2604,9 +2604,19 @@ pub enum Rvalue<'tcx> {
|
|||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
static_assert_size!(Rvalue<'_>, 40);
|
||||
|
||||
impl<'tcx> Rvalue<'tcx> {
|
||||
#[inline]
|
||||
pub fn is_pointer_int_cast(&self) -> bool {
|
||||
matches!(self, Rvalue::Cast(CastKind::PointerAddress, _, _))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub enum CastKind {
|
||||
Misc,
|
||||
/// A pointer to address cast. A cast between a pointer and an integer type,
|
||||
/// or between a function pointer and an integer type.
|
||||
PointerAddress,
|
||||
Pointer(PointerCast),
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
|
||||
use crate::mir::*;
|
||||
use crate::ty::cast::CastTy;
|
||||
use crate::ty::subst::Subst;
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use rustc_hir as hir;
|
||||
|
@ -224,22 +223,6 @@ impl<'tcx> Rvalue<'tcx> {
|
|||
_ => RvalueInitializationState::Deep,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_pointer_int_cast<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> bool
|
||||
where
|
||||
D: HasLocalDecls<'tcx>,
|
||||
{
|
||||
if let Rvalue::Cast(CastKind::Misc, src_op, dest_ty) = self {
|
||||
if let Some(CastTy::Int(_)) = CastTy::from_ty(*dest_ty) {
|
||||
let src_ty = src_op.ty(local_decls, tcx);
|
||||
if let Some(CastTy::FnPtr | CastTy::Ptr(_)) = CastTy::from_ty(src_ty) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Operand<'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue