Skip to content

Commit 3fec060

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents bd25039 + 6f5c799 commit 3fec060

File tree

16 files changed

+70
-35
lines changed

16 files changed

+70
-35
lines changed

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl NewPermission {
136136
cx: &crate::MiriInterpCx<'_, 'tcx>,
137137
) -> Self {
138138
// `ty` is not the `Box` but the field of the Box with this pointer (due to allocator handling).
139-
let pointee = ty.builtin_deref(true).unwrap().ty;
139+
let pointee = ty.builtin_deref(true).unwrap();
140140
if pointee.is_unpin(*cx.tcx, cx.param_env()) {
141141
// A regular box. On `FnEntry` this is `noalias`, but not `dereferenceable` (hence only
142142
// a weak protector).

src/borrow_tracker/tree_borrows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'tcx> NewPermission {
173173
cx: &crate::MiriInterpCx<'_, 'tcx>,
174174
zero_size: bool,
175175
) -> Option<Self> {
176-
let pointee = ty.builtin_deref(true).unwrap().ty;
176+
let pointee = ty.builtin_deref(true).unwrap();
177177
pointee.is_unpin(*cx.tcx, cx.param_env()).then_some(()).map(|()| {
178178
// Regular `Unpin` box, give it `noalias` but only a weak protector
179179
// because it is valid to deallocate it within the function.

src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
117117

118118
"write_bytes" | "volatile_set_memory" => {
119119
let [ptr, val_byte, count] = check_arg_count(args)?;
120-
let ty = ptr.layout.ty.builtin_deref(true).unwrap().ty;
120+
let ty = ptr.layout.ty.builtin_deref(true).unwrap();
121121
let ty_layout = this.layout_of(ty)?;
122122
let val_byte = this.read_scalar(val_byte)?.to_u8()?;
123123
let ptr = this.read_pointer(ptr)?;

src/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
267267
Op::WrappingOffset => {
268268
let ptr = left.to_scalar().to_pointer(this)?;
269269
let offset_count = right.to_scalar().to_target_isize(this)?;
270-
let pointee_ty = left.layout.ty.builtin_deref(true).unwrap().ty;
270+
let pointee_ty = left.layout.ty.builtin_deref(true).unwrap();
271271

272272
let pointee_size = i64::try_from(this.layout_of(pointee_ty)?.size.bytes()).unwrap();
273273
let offset_bytes = offset_count.wrapping_mul(pointee_size);

src/shims/unix/foreign_items.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
378378
.builtin_deref(true)
379379
.ok_or_else(|| err_ub_format!(
380380
"wrong signature used for `pthread_key_create`: first argument must be a raw pointer."
381-
))?
382-
.ty;
381+
))?;
383382
let key_layout = this.layout_of(key_type)?;
384383

385384
// Create key and write it into the memory where `key_ptr` wants it.

src/shims/x86/avx2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::rustc_middle::ty::layout::LayoutOf as _;
21
use rustc_middle::mir;
2+
use rustc_middle::ty::layout::LayoutOf as _;
33
use rustc_middle::ty::Ty;
44
use rustc_span::Symbol;
55
use rustc_target::spec::abi::Abi;

tests/fail/enum-set-discriminant-niche-variant-wrong.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(custom_mir)]
33

44
use std::intrinsics::mir::*;
5-
use std::num::NonZeroI32;
5+
use std::num::NonZero;
66

77
// We define our own option type so that we can control the variant indices.
88
#[allow(unused)]
@@ -13,7 +13,7 @@ enum Option<T> {
1313
use Option::*;
1414

1515
#[custom_mir(dialect = "runtime", phase = "optimized")]
16-
fn set_discriminant(ptr: &mut Option<NonZeroI32>) {
16+
fn set_discriminant(ptr: &mut Option<NonZero<i32>>) {
1717
mir! {
1818
{
1919
// We set the discriminant to `Some`, which is a NOP since this is the niched variant.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::num::*;
1+
use std::num::NonZero;
22

33
#[repr(C)]
4-
struct S1(NonZeroI32);
4+
struct S1(NonZero<i32>);
55

66
#[repr(C)]
77
struct S2(i32);
@@ -11,6 +11,6 @@ fn callee(_s: S2) {}
1111
fn main() {
1212
let fnptr: fn(S2) = callee;
1313
let fnptr: fn(S1) = unsafe { std::mem::transmute(fnptr) };
14-
fnptr(S1(NonZeroI32::new(1).unwrap()));
14+
fnptr(S1(NonZero::new(1).unwrap()));
1515
//~^ ERROR: calling a function with argument of type S2 passing data of type S1
1616
}

tests/fail/function_pointers/abi_mismatch_repr_C.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: calling a function with argument of type S2 passing data of type S1
22
--> $DIR/abi_mismatch_repr_C.rs:LL:CC
33
|
4-
LL | fnptr(S1(NonZeroI32::new(1).unwrap()));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with argument of type S2 passing data of type S1
4+
LL | fnptr(S1(NonZero::new(1).unwrap()));
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with argument of type S2 passing data of type S1
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(strict_provenance)]
2+
use core::ptr;
3+
4+
fn main() {
5+
unsafe {
6+
let base = ptr::without_provenance::<()>(10);
7+
let unit = &*base;
8+
let p1 = unit as *const ();
9+
10+
let base = ptr::without_provenance::<()>(11);
11+
let unit = &*base;
12+
let p2 = unit as *const ();
13+
14+
// Seems to work because they are same pointer
15+
// even though it's dangling.
16+
let _ = p1.byte_offset_from(p1);
17+
18+
// UB because different pointers.
19+
let _ = p1.byte_offset_from(p2); //~ERROR: different pointers without provenance
20+
}
21+
}

0 commit comments

Comments
 (0)