diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-04-25 12:10:55 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-04-25 19:23:45 -0700 |
| commit | 05a665f21a6f9763d136a9d2d7c0255de6d333fb (patch) | |
| tree | 4735216a1581cc3a65ede2d7d7b7b49f9ca6b730 /compiler/rustc_const_eval | |
| parent | a7aa20517c80161a2ffe7c0c25fc2e0140c43c90 (diff) | |
| download | rust-05a665f21a6f9763d136a9d2d7c0255de6d333fb.tar.gz rust-05a665f21a6f9763d136a9d2d7c0255de6d333fb.zip | |
Lower `intrinsics::offset` to `mir::BinOp::Offset`
They're semantically the same, so this means the backends don't need to handle the intrinsic and means fewer MIR basic blocks in pointer arithmetic code.
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/const_eval/machine.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/intrinsics.rs | 8 |
2 files changed, 13 insertions, 12 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 814b67b46ec..bfca58a15b3 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -559,11 +559,20 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, } fn binary_ptr_op( - _ecx: &InterpCx<'mir, 'tcx, Self>, - _bin_op: mir::BinOp, - _left: &ImmTy<'tcx>, - _right: &ImmTy<'tcx>, + ecx: &InterpCx<'mir, 'tcx, Self>, + bin_op: mir::BinOp, + left: &ImmTy<'tcx>, + right: &ImmTy<'tcx>, ) -> InterpResult<'tcx, (Scalar, bool, Ty<'tcx>)> { + if bin_op == mir::BinOp::Offset { + let ptr = left.to_scalar().to_pointer(ecx)?; + let offset_count = right.to_scalar().to_target_isize(ecx)?; + let pointee_ty = left.layout.ty.builtin_deref(true).unwrap().ty; + + let offset_ptr = ecx.ptr_offset_inbounds(ptr, pointee_ty, offset_count)?; + return Ok((Scalar::from_maybe_pointer(offset_ptr, ecx), false, left.layout.ty)); + } + throw_unsup_format!("pointer arithmetic or comparison is not supported at compile-time"); } diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index eada75ae391..a77c699c22f 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -286,14 +286,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { sym::write_bytes => { self.write_bytes_intrinsic(&args[0], &args[1], &args[2])?; } - sym::offset => { - let ptr = self.read_pointer(&args[0])?; - let offset_count = self.read_target_isize(&args[1])?; - let pointee_ty = substs.type_at(0); - - let offset_ptr = self.ptr_offset_inbounds(ptr, pointee_ty, offset_count)?; - self.write_pointer(offset_ptr, dest)?; - } sym::arith_offset => { let ptr = self.read_pointer(&args[0])?; let offset_count = self.read_target_isize(&args[1])?; |
