rename PointerAddress → PointerExposeAddress

This commit is contained in:
Ralf Jung 2022-06-01 13:24:44 -04:00
parent 395a09c3da
commit 4dc5d457d8
12 changed files with 23 additions and 18 deletions

View File

@ -2147,7 +2147,7 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
} }
} }
CastKind::PointerAddress => { CastKind::PointerExposeAddress => {
let ty_from = op.ty(body, tcx); let ty_from = op.ty(body, tcx);
let cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_from = CastTy::from_ty(ty_from);
let cast_ty_to = CastTy::from_ty(*ty); let cast_ty_to = CastTy::from_ty(*ty);

View File

@ -607,7 +607,11 @@ fn codegen_stmt<'tcx>(
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout)); lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
} }
Rvalue::Cast(CastKind::Misc | CastKind::PointerAddress, ref operand, to_ty) => { Rvalue::Cast(
CastKind::Misc | CastKind::PointerExposeAddress,
ref operand,
to_ty,
) => {
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
let from_ty = operand.layout().ty; let from_ty = operand.layout().ty;
let to_ty = fx.monomorphize(to_ty); let to_ty = fx.monomorphize(to_ty);

View File

@ -181,7 +181,7 @@ pub fn codegen_rvalue_operand(
let cast = bx.cx().layout_of(self.monomorphize(mir_cast_ty)); let cast = bx.cx().layout_of(self.monomorphize(mir_cast_ty));
let val = match *kind { let val = match *kind {
mir::CastKind::PointerAddress => { mir::CastKind::PointerExposeAddress => {
assert!(bx.cx().is_backend_immediate(cast)); assert!(bx.cx().is_backend_immediate(cast));
let llptr = operand.immediate(); let llptr = operand.immediate();
let llcast_ty = bx.cx().immediate_backend_type(cast); let llcast_ty = bx.cx().immediate_backend_type(cast);

View File

@ -31,9 +31,9 @@ pub fn cast(
self.unsize_into(src, cast_ty, dest)?; self.unsize_into(src, cast_ty, dest)?;
} }
PointerAddress => { PointerExposeAddress => {
let src = self.read_immediate(src)?; let src = self.read_immediate(src)?;
let res = self.pointer_address_cast(&src, cast_ty)?; let res = self.pointer_expose_address_cast(&src, cast_ty)?;
self.write_immediate(res, dest)?; self.write_immediate(res, dest)?;
} }
@ -184,7 +184,7 @@ pub fn misc_cast(
Ok(self.cast_from_int_like(scalar, src.layout, cast_ty)?.into()) Ok(self.cast_from_int_like(scalar, src.layout, cast_ty)?.into())
} }
pub fn pointer_address_cast( pub fn pointer_expose_address_cast(
&mut self, &mut self,
src: &ImmTy<'tcx, M::PointerTag>, src: &ImmTy<'tcx, M::PointerTag>,
cast_ty: Ty<'tcx>, cast_ty: Ty<'tcx>,

View File

@ -542,7 +542,7 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
// in the type of any local, which also excludes casts). // in the type of any local, which also excludes casts).
} }
Rvalue::Cast(CastKind::PointerAddress, _, _) => { Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => {
self.check_op(ops::RawPtrToIntCast); self.check_op(ops::RawPtrToIntCast);
} }

View File

@ -502,7 +502,7 @@ fn validate_rvalue(&mut self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable>
Rvalue::ThreadLocalRef(_) => return Err(Unpromotable), Rvalue::ThreadLocalRef(_) => return Err(Unpromotable),
// ptr-to-int casts are not possible in consts and thus not promotable // ptr-to-int casts are not possible in consts and thus not promotable
Rvalue::Cast(CastKind::PointerAddress, _, _) => return Err(Unpromotable), Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => return Err(Unpromotable),
// int-to-ptr casts are fine, they just use the integer value at pointer type. // int-to-ptr casts are fine, they just use the integer value at pointer type.
Rvalue::Cast(_, operand, _) => { Rvalue::Cast(_, operand, _) => {

View File

@ -2607,16 +2607,17 @@ pub enum Rvalue<'tcx> {
impl<'tcx> Rvalue<'tcx> { impl<'tcx> Rvalue<'tcx> {
#[inline] #[inline]
pub fn is_pointer_int_cast(&self) -> bool { pub fn is_pointer_int_cast(&self) -> bool {
matches!(self, Rvalue::Cast(CastKind::PointerAddress, _, _)) matches!(self, Rvalue::Cast(CastKind::PointerExposeAddress, _, _))
} }
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] #[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
pub enum CastKind { pub enum CastKind {
Misc, Misc,
/// A pointer to address cast. A cast between a pointer and an integer type, /// An exposing pointer to address cast. A cast between a pointer and an integer type, or
/// or between a function pointer and an integer type. /// between a function pointer and an integer type.
PointerAddress, /// See the docs on `expose_addr` for more details.
PointerExposeAddress,
Pointer(PointerCast), Pointer(PointerCast),
} }

View File

@ -194,7 +194,7 @@ pub(crate) fn as_rvalue(
let cast_ty = CastTy::from_ty(expr.ty); let cast_ty = CastTy::from_ty(expr.ty);
let cast_kind = match (from_ty, cast_ty) { let cast_kind = match (from_ty, cast_ty) {
(Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => { (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => {
CastKind::PointerAddress CastKind::PointerExposeAddress
} }
(_, _) => CastKind::Misc, (_, _) => CastKind::Misc,
}; };

View File

@ -21,7 +21,7 @@
// + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 // + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16
// + literal: Const { ty: &i32, val: Unevaluated(FOO, [], None) } // + literal: Const { ty: &i32, val: Unevaluated(FOO, [], None) }
_2 = &raw const (*_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 _2 = &raw const (*_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16
_1 = move _2 as usize (PointerAddress); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:39 _1 = move _2 as usize (PointerExposeAddress); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:39
StorageDead(_2); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:38: 7:39 StorageDead(_2); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:38: 7:39
StorageDead(_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:39: 7:40 StorageDead(_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:39: 7:40
StorageLive(_4); // scope 1 at $DIR/const_prop_fails_gracefully.rs:8:5: 8:12 StorageLive(_4); // scope 1 at $DIR/const_prop_fails_gracefully.rs:8:5: 8:12

View File

@ -17,7 +17,7 @@
// mir::Constant // mir::Constant
// + span: $DIR/reify_fn_ptr.rs:4:13: 4:17 // + span: $DIR/reify_fn_ptr.rs:4:13: 4:17
// + literal: Const { ty: fn() {main}, val: Value(Scalar(<ZST>)) } // + literal: Const { ty: fn() {main}, val: Value(Scalar(<ZST>)) }
_2 = move _3 as usize (PointerAddress); // scope 0 at $DIR/reify_fn_ptr.rs:4:13: 4:26 _2 = move _3 as usize (PointerExposeAddress); // scope 0 at $DIR/reify_fn_ptr.rs:4:13: 4:26
StorageDead(_3); // scope 0 at $DIR/reify_fn_ptr.rs:4:25: 4:26 StorageDead(_3); // scope 0 at $DIR/reify_fn_ptr.rs:4:25: 4:26
_1 = move _2 as *const fn() (Misc); // scope 0 at $DIR/reify_fn_ptr.rs:4:13: 4:41 _1 = move _2 as *const fn() (Misc); // scope 0 at $DIR/reify_fn_ptr.rs:4:13: 4:41
StorageDead(_2); // scope 0 at $DIR/reify_fn_ptr.rs:4:40: 4:41 StorageDead(_2); // scope 0 at $DIR/reify_fn_ptr.rs:4:40: 4:41

View File

@ -19,12 +19,12 @@
StorageLive(_2); // scope 0 at $DIR/provenance_soundness.rs:8:9: 8:11 StorageLive(_2); // scope 0 at $DIR/provenance_soundness.rs:8:9: 8:11
StorageLive(_3); // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:15 StorageLive(_3); // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:15
_3 = _1; // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:15 _3 = _1; // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:15
_2 = move _3 as usize (PointerAddress); // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:24 _2 = move _3 as usize (PointerExposeAddress); // scope 0 at $DIR/provenance_soundness.rs:8:14: 8:24
StorageDead(_3); // scope 0 at $DIR/provenance_soundness.rs:8:23: 8:24 StorageDead(_3); // scope 0 at $DIR/provenance_soundness.rs:8:23: 8:24
StorageLive(_4); // scope 1 at $DIR/provenance_soundness.rs:9:9: 9:11 StorageLive(_4); // scope 1 at $DIR/provenance_soundness.rs:9:9: 9:11
StorageLive(_5); // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:15 StorageLive(_5); // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:15
_5 = _1; // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:15 _5 = _1; // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:15
_4 = move _5 as isize (PointerAddress); // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:24 _4 = move _5 as isize (PointerExposeAddress); // scope 1 at $DIR/provenance_soundness.rs:9:14: 9:24
StorageDead(_5); // scope 1 at $DIR/provenance_soundness.rs:9:23: 9:24 StorageDead(_5); // scope 1 at $DIR/provenance_soundness.rs:9:23: 9:24
_0 = const (); // scope 0 at $DIR/provenance_soundness.rs:7:32: 10:2 _0 = const (); // scope 0 at $DIR/provenance_soundness.rs:7:32: 10:2
StorageDead(_4); // scope 1 at $DIR/provenance_soundness.rs:10:1: 10:2 StorageDead(_4); // scope 1 at $DIR/provenance_soundness.rs:10:1: 10:2

View File

@ -125,7 +125,7 @@ fn check_rvalue<'tcx>(
Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
check_place(tcx, *place, span, body) check_place(tcx, *place, span, body)
}, },
Rvalue::Cast(CastKind::PointerAddress, _, _) => { Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => {
Err((span, "casting pointers to ints is unstable in const fn".into())) Err((span, "casting pointers to ints is unstable in const fn".into()))
}, },
Rvalue::Cast(CastKind::Misc, operand, _) => { Rvalue::Cast(CastKind::Misc, operand, _) => {