8000 Rollup of 7 pull requests by RalfJung · Pull Request #72733 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 7 pull requests #72733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3f661d2
borrowck `DefId` -> `LocalDefId`
lcnr May 11, 2020
a8ed9aa
impl From<[T; N]> for Box<[T]>
pickfire Apr 13, 2020
eccaa01
rustc_target: Add a target spec option for static-pie support
petrochenkov May 1, 2020
96a466c
linker: Support `-static-pie` and `-static -shared`
petrochenkov May 1, 2020
08df311
librustc_mir: Add support for const fn offset/arith_offset
josephlr Apr 24, 2020
9b3dfd8
core: Make pointer offset methods "const fn"
josephlr Apr 24, 2020
88a37a2
test/ui/consts: Add tests for const ptr offsets
josephlr May 15, 2020
6b20f58
miri_unleached: We now allow offset in const fn
josephlr May 18, 2020
55577b4
librustc_mir: Add back use statement
josephlr May 25, 2020
6367b54
librustc_middle: Add function for computing unsigned abs
josephlr May 26, 2020
71ef841
Add checks and tests for computing abs(offset_bytes)
josephlr May 26, 2020
822ad87
Add Peekable::next_if
jyn514 May 18, 2020
a977df3
Implement RFC 2585
LeSeulArtichaut May 3, 2020
594c499
Add tests
LeSeulArtichaut May 3, 2020
bb67915
Apply suggestions from code review
LeSeulArtichaut May 13, 2020
3ce9d5c
Add more cases to the test
LeSeulArtichaut May 14, 2020
b3e012b
Fix inverted `if` condition
LeSeulArtichaut May 18, 2020
a41f763
Use the lowest of `unsafe_op_in_unsafe_fn` and `safe_borrow_packed` f…
LeSeulArtichaut May 18, 2020
a3bae5c
Fix wrong conflict resolution
LeSeulArtichaut May 19, 2020
925d5ac
Fix and bless tests
LeSeulArtichaut May 21, 2020
9671b44
Add tests for packed borrows in unsafe fns
LeSeulArtichaut May 22, 2020
3599ada
Mark deduplicated errors as expected in gate test
LeSeulArtichaut May 23, 2020
4a538d3
Do not hardcode lint name
LeSeulArtichaut May 23, 2020
e3d27ec
Add explanation about taking the minimum of the two lints
LeSeulArtichaut May 23, 2020
1b08850
Fix import
LeSeulArtichaut May 23, 2020
63066c0
Use `LintId`s to check for gated lints
LeSeulArtichaut May 23, 2020
db684be
Whitelist `unsafe_op_in_unsafe_fn` in rustdoc
LeSeulArtichaut May 27, 2020
3fea832
Fix spacing of expected/found notes without a label
estebank Dec 20, 2019
5ba2220
Name `RegionKind::ReVar` lifetimes in diagnostics
estebank Dec 20, 2019
eb0f4d5
Tweak output for mismatched impl item
estebank Dec 22, 2019
3811232
review comments
estebank Dec 23, 2019
2e2f820
review comment: use FxIndexSet
estebank Dec 27, 2019
d0d30b0
fix rebase
estebank Jan 7, 2020
2b35247
Modify wording
estebank Feb 17, 2020
500504c
fix rebase
estebank Mar 30, 2020
c52dbbc
fix rebase
estebank Apr 14, 2020
7d5415b
Add additional checks for isize overflow
josephlr May 27, 2020
cb6408a
Fix rebase
estebank May 28, 2020
f213acf
review comments: change wording and visual output
estebank May 28, 2020
0e3b31c
Update src/librustdoc/core.rs
nikomatsakis May 28, 2020
1bd6970
Account for `Self` as a type param
estebank May 28, 2020
ce10b6d
Rollup merge of #67460 - estebank:named-lts, r=nikomatsakis
RalfJung May 29, 2020
de90e0d
Rollup merge of #71095 - pickfire:box-from-array, r=dtolnay
RalfJung May 29, 2020
b014e61
Rollup merge of #71500 - josephlr:offset, r=oli-obk,RalfJung
RalfJung May 29, 2020
b08168e
Rollup merge of #71804 - petrochenkov:static-pie, r=cuviper
RalfJung May 29, 2020
4e2351e
Rollup merge of #71862 - LeSeulArtichaut:unsafe-block-in-unsafe-fn, r…
RalfJung May 29, 2020
92329c7
Rollup merge of #72103 - lcnr:borrowck-localdefid, r=jonas-schievink
RalfJung May 29, 2020
783cfb1
Rollup merge of #72310 - jyn514:peekable-next-if, r=dtolnay
RalfJung May 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
< 8000 div data-target="diff-layout.mainContainer" data-view-component="true" class="Layout-main">
Prev Previous commit
Next Next commit
librustc_mir: Add support for const fn offset/arith_offset
Miri's pointer_offset_inbounds implementation has been moved into
librustc_mir as ptr_offset_inbounds (to avoid breaking miri on a
nightly update). The comments have been slightly reworked to better
match `offset`'s external documentation about what causes UB.

The intrinsic implementations are taken directly from miri.

Signed-off-by: Joe Richey <joerichey@google.com>
  • Loading branch information
josephlr committed May 25, 2020
commit 08df3116e92356311735be2d0c588d461e16fbff
53 changes: 51 additions & 2 deletions src/librustc_mir/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use rustc_middle::mir::{
};
use rustc_middle::ty;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::{Ty, TyCtxt};
use rustc_span::symbol::{sym, Symbol};
use rustc_target::abi::{Abi, LayoutOf as _, Primitive, Size};

use super::{ImmTy, InterpCx, Machine, OpTy, PlaceTy};
use super::{CheckInAllocMsg, ImmTy, InterpCx, Machine, OpTy, PlaceTy};

mod caller_location;
mod type_name;
Expand Down Expand Up @@ -279,7 +279,24 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let result = Scalar::from_uint(truncated_bits, layout.size);
self.write_scalar(result, dest)?;
}
sym::offset => {
let ptr = self.read_scalar(args[0])?.not_undef()?;
let offset_count = self.read_scalar(args[1])?.to_machine_isize(self)?;
let pointee_ty = substs.type_at(0);

let offset_ptr = self.ptr_offset_inbounds(ptr, pointee_ty, offset_count)?;
self.write_scalar(offset_ptr, dest)?;
}
sym::arith_offset => {
let ptr = self.read_scalar(args[0])?.not_undef()?;
let offset_count = self.read_scalar(args[1])?.to_machine_isize(self)?;
let pointee_ty = substs.type_at(0);

let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
let offset_bytes = offset_count.wrapping_mul(pointee_size);
let offset_ptr = ptr.ptr_wrapping_signed_offset(offset_bytes, self);
self.write_scalar(offset_ptr, dest)?;
}
sym::ptr_offset_from => {
let a = self.read_immediate(args[0])?.to_scalar()?;
let b = self.read_immediate(args[1])?.to_scalar()?;
Expand Down Expand Up @@ -409,4 +426,36 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// `Rem` says this is all right, so we can let `Div` do its job.
self.binop_ignore_overflow(BinOp::Div, a, b, dest)
}

/// Offsets a pointer by some multiple of its type, returning an error if the pointer leaves its
/// allocation. For integer pointers, we consider each of them their own tiny allocation of size
/// 0, so offset-by-0 (and only 0) is okay -- except that NULL cannot be offset by _any_ value.
pub fn ptr_offset_inbounds(
&self,
ptr: Scalar<M::PointerTag>,
pointee_ty: Ty<'tcx>,
offset_count: i64,
) -> InterpResult<'tcx, Scalar<M::PointerTag>> {
let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
// The computed offset, in bytes, cannot overflow an isize.
let offset_bytes = offset_count
.checked_mul(pointee_size)
.ok_or(err_ub_format!("inbounds pointer arithmetic: overflow computing offset"))?;
// The offset being in bounds cannot rely on "wrapping around" the address space.
// So, first rule out overflows in the pointer arithmetic.
let offset_ptr = ptr.ptr_signed_offset(offset_bytes, self)?;
// ptr and offset_ptr must be in bounds of the same allocated object. This means all of the
// memory between these pointers must be accessible. Note that we do not require the
// pointers to be properly aligned (unlike a read/write operation).
let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr };
let size = offset_bytes.checked_abs().unwrap();
// This call handles checking for integer/NULL pointers.
self.memory.check_ptr_access_align(
min_ptr,
Size::from_bytes(size),
None,
CheckInAllocMsg::InboundsTest,
)?;
Ok(offset_ptr)
}
}
2 changes: 2 additions & 0 deletions src/librustc_span/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ symbols! {
Arc,
Arguments,
ArgumentV1,
arith_offset,
arm_target_feature,
asm,
assert,
Expand Down Expand Up @@ -516,6 +517,7 @@ symbols! {
not,
note,
object_safe_for_dispatch,
offset,
Ok,
omit_gdb_pretty_printer_section,
on,
Expand Down
0