From 4dc5d457d86f7414b1a2b4d81bf7428b3ffcbb34 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 1 Jun 2022 13:24:44 -0400 Subject: [PATCH] =?UTF-8?q?rename=20PointerAddress=20=E2=86=92=20PointerEx?= =?UTF-8?q?poseAddress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- compiler/rustc_codegen_cranelift/src/base.rs | 6 +++++- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 2 +- compiler/rustc_const_eval/src/interpret/cast.rs | 6 +++--- .../rustc_const_eval/src/transform/check_consts/check.rs | 2 +- .../rustc_const_eval/src/transform/promote_consts.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 9 +++++---- compiler/rustc_mir_build/src/build/expr/as_rvalue.rs | 2 +- .../const_prop_fails_gracefully.main.ConstProp.diff | 2 +- .../mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff | 2 +- ...ce_soundness.pointer_to_int.DeadStoreElimination.diff | 4 ++-- .../clippy/clippy_utils/src/qualify_min_const_fn.rs | 2 +- 12 files changed, 23 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index d9d31ab2c89..abf77acb8c7 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -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 cast_ty_from = CastTy::from_ty(ty_from); let cast_ty_to = CastTy::from_ty(*ty); diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index 7c59ce354c0..58bec183c94 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -607,7 +607,11 @@ fn codegen_stmt<'tcx>( let operand = codegen_operand(fx, operand); 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 from_ty = operand.layout().ty; let to_ty = fx.monomorphize(to_ty); diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index bd88aa33372..6ff8d4aa442 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -181,7 +181,7 @@ pub fn codegen_rvalue_operand( let cast = bx.cx().layout_of(self.monomorphize(mir_cast_ty)); let val = match *kind { - mir::CastKind::PointerAddress => { + mir::CastKind::PointerExposeAddress => { assert!(bx.cx().is_backend_immediate(cast)); let llptr = operand.immediate(); let llcast_ty = bx.cx().immediate_backend_type(cast); diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index af563c1450e..520ae409e6b 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -31,9 +31,9 @@ pub fn cast( self.unsize_into(src, cast_ty, dest)?; } - PointerAddress => { + PointerExposeAddress => { 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)?; } @@ -184,7 +184,7 @@ pub fn misc_cast( 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, src: &ImmTy<'tcx, M::PointerTag>, cast_ty: Ty<'tcx>, diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 4ef33d62a6b..c07680515f4 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -542,7 +542,7 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { // in the type of any local, which also excludes casts). } - Rvalue::Cast(CastKind::PointerAddress, _, _) => { + Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => { self.check_op(ops::RawPtrToIntCast); } diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index ea23bd14d25..cf5d7b6c70a 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -502,7 +502,7 @@ fn validate_rvalue(&mut self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> Rvalue::ThreadLocalRef(_) => return Err(Unpromotable), // 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. Rvalue::Cast(_, operand, _) => { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 1b63c8d67ca..d9cdca8bcb5 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2607,16 +2607,17 @@ pub enum Rvalue<'tcx> { impl<'tcx> Rvalue<'tcx> { #[inline] 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)] 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, + /// An exposing pointer to address cast. A cast between a pointer and an integer type, or + /// between a function pointer and an integer type. + /// See the docs on `expose_addr` for more details. + PointerExposeAddress, Pointer(PointerCast), } diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index 2b137046c7f..7d08b20631e 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -194,7 +194,7 @@ pub(crate) fn as_rvalue( let cast_ty = CastTy::from_ty(expr.ty); let cast_kind = match (from_ty, cast_ty) { (Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => { - CastKind::PointerAddress + CastKind::PointerExposeAddress } (_, _) => CastKind::Misc, }; diff --git a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff index 4fdd4b2b4bb..84d72202d52 100644 --- a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff @@ -21,7 +21,7 @@ // + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 // + 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 - _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(_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 diff --git a/src/test/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff b/src/test/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff index 7eb34ed5469..04724b13ca6 100644 --- a/src/test/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/reify_fn_ptr.main.ConstProp.diff @@ -17,7 +17,7 @@ // mir::Constant // + span: $DIR/reify_fn_ptr.rs:4:13: 4:17 // + literal: Const { ty: fn() {main}, val: Value(Scalar()) } - _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 _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 diff --git a/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff b/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff index bf32245e300..2331f63ecdd 100644 --- a/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff +++ b/src/test/mir-opt/dead-store-elimination/provenance_soundness.pointer_to_int.DeadStoreElimination.diff @@ -19,12 +19,12 @@ 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 _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 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 _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 _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 diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 283b20fc24d..b1c82ac76e8 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -125,7 +125,7 @@ fn check_rvalue<'tcx>( Rvalue::Len(place) | Rvalue::Discriminant(place) | Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { 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())) }, Rvalue::Cast(CastKind::Misc, operand, _) => {