Skip to content

Commit

Permalink
Auto merge of #123396 - jhpratt:rollup-oa54mh1, r=jhpratt
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #122865 (Split hir ty lowerer's error reporting code in check functions to mod errors.)
 - #122935 (rename ptr::from_exposed_addr -> ptr::with_exposed_provenance)
 - #123182 (Avoid expanding to unstable internal method)
 - #123203 (Add `Context::ext`)
 - #123380 (Improve bootstrap comments)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 3, 2024
2 parents 11e17ca + f431b38 commit f2bb429
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ environment variable. We first document the most relevant and most commonly used
number of available CPUs is `1`. Note that this flag does not affect how miri handles threads in
any way.
* `-Zmiri-permissive-provenance` disables the warning for integer-to-pointer casts and
[`ptr::from_exposed_addr`](https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html).
[`ptr::with_exposed_provenance`](https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html).
This will necessarily miss some bugs as those operations are not efficiently and accurately
implementable in a sanitizer, but it will only miss bugs that concern memory/pointers which is
subject to these operations.
Expand Down
6 changes: 3 additions & 3 deletions src/alloc_addresses/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use reuse_pool::ReusePool;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ProvenanceMode {
/// We support `expose_addr`/`from_exposed_addr` via "wildcard" provenance.
/// However, we want on `from_exposed_addr` to alert the user of the precision loss.
/// We support `expose_addr`/`with_exposed_provenance` via "wildcard" provenance.
/// However, we want on `with_exposed_provenance` to alert the user of the precision loss.
Default,
/// Like `Default`, but without the warning.
Permissive,
/// We error on `from_exposed_addr`, ensuring no precision loss.
/// We error on `with_exposed_provenance`, ensuring no precision loss.
Strict,
}

Expand Down
8 changes: 4 additions & 4 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl fmt::Display for TerminationInfo {
Int2PtrWithStrictProvenance =>
write!(
f,
"integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`"
"integer-to-pointer casts and `ptr::with_exposed_provenance` are not supported with `-Zmiri-strict-provenance`"
),
StackedBorrowsUb { msg, .. } => write!(f, "{msg}"),
TreeBorrowsUb { title, .. } => write!(f, "{title}"),
Expand Down Expand Up @@ -593,7 +593,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
(
None,
format!(
"This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,"
"This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,"
),
),
(
Expand All @@ -603,7 +603,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
(
None,
format!(
"See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation."
"See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation."
),
),
(
Expand All @@ -615,7 +615,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
(
None,
format!(
"You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics."
"You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics."
),
),
(
Expand Down
6 changes: 3 additions & 3 deletions src/shims/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
dest.transmute(this.machine.layouts.uint(dest.layout.size).unwrap(), this)?;
this.write_int(res, &dest)?;
}
"cast" | "as" | "cast_ptr" | "expose_addr" | "from_exposed_addr" => {
"cast" | "as" | "cast_ptr" | "expose_addr" | "with_exposed_provenance" => {
let [op] = check_arg_count(args)?;
let (op, op_len) = this.operand_to_simd(op)?;
let (dest, dest_len) = this.mplace_to_simd(dest)?;
Expand All @@ -525,7 +525,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let safe_cast = intrinsic_name == "as";
let ptr_cast = intrinsic_name == "cast_ptr";
let expose_cast = intrinsic_name == "expose_addr";
let from_exposed_cast = intrinsic_name == "from_exposed_addr";
let from_exposed_cast = intrinsic_name == "with_exposed_provenance";

for i in 0..dest_len {
let op = this.read_immediate(&this.project_index(&op, i)?)?;
Expand Down Expand Up @@ -559,7 +559,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
(ty::RawPtr(..), ty::Int(_) | ty::Uint(_)) if expose_cast =>
this.pointer_expose_address_cast(&op, dest.layout)?,
(ty::Int(_) | ty::Uint(_), ty::RawPtr(..)) if from_exposed_cast =>
this.pointer_from_exposed_address_cast(&op, dest.layout)?,
this.pointer_with_exposed_provenance_cast(&op, dest.layout)?,
// Error otherwise
_ =>
throw_unsup_format!(
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/provenance/ptr_int_unexposed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fn main() {

let x_usize: usize = x_ptr.addr();
// Cast back an address that did *not* get exposed.
let ptr = std::ptr::from_exposed_addr::<i32>(x_usize);
let ptr = std::ptr::with_exposed_provenance::<i32>(x_usize);
assert_eq!(unsafe { *ptr }, 3); //~ ERROR: is a dangling pointer
}
2 changes: 1 addition & 1 deletion tests/fail/provenance/strict_provenance_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

fn main() {
let addr = &0 as *const i32 as usize;
let _ptr = std::ptr::from_exposed_addr::<i32>(addr); //~ ERROR: integer-to-pointer casts and `ptr::from_exposed_addr` are not supported
let _ptr = std::ptr::with_exposed_provenance::<i32>(addr); //~ ERROR: integer-to-pointer casts and `ptr::with_exposed_provenance` are not supported
}
6 changes: 3 additions & 3 deletions tests/fail/provenance/strict_provenance_cast.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unsupported operation: integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
error: unsupported operation: integer-to-pointer casts and `ptr::with_exposed_provenance` are not supported with `-Zmiri-strict-provenance`
--> $DIR/strict_provenance_cast.rs:LL:CC
|
LL | let _ptr = std::ptr::from_exposed_addr::<i32>(addr);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
LL | let _ptr = std::ptr::with_exposed_provenance::<i32>(addr);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer casts and `ptr::with_exposed_provenance` are not supported with `-Zmiri-strict-provenance`
|
= help: use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead
= note: BACKTRACE:
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/stacked_borrows/exposed_only_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fn main() {
let mut x = 0;
let _fool = &mut x as *mut i32; // this would have fooled the old untagged pointer logic
let addr = (&x as *const i32).expose_addr();
let ptr = std::ptr::from_exposed_addr_mut::<i32>(addr);
let ptr = std::ptr::with_exposed_provenance_mut::<i32>(addr);
unsafe { *ptr = 0 }; //~ ERROR: /write access using <wildcard> .* no exposed tags have suitable permission in the borrow stack/
}
6 changes: 3 additions & 3 deletions tests/pass/box.stack.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ warning: integer-to-pointer cast
LL | let r2 = ((r as usize) + 0) as *mut i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
|
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,
= help: which means that Miri might miss pointer bugs in this program.
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation.
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics.
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
= note: BACKTRACE:
= note: inside `into_raw` at $DIR/box.rs:LL:CC
Expand Down
6 changes: 3 additions & 3 deletions tests/pass/extern_types.stack.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ warning: integer-to-pointer cast
LL | let x: &Foo = unsafe { &*(16 as *const Foo) };
| ^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
|
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,
= help: which means that Miri might miss pointer bugs in this program.
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation.
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics.
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
= note: BACKTRACE:
= note: inside `main` at $DIR/extern_types.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/pass/portable-simd-ptrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ fn main() {
// Pointer casts
let _val: Simd<*const u8, 4> = Simd::<*const i32, 4>::splat(ptr::null()).cast();
let addrs = Simd::<*const i32, 4>::splat(ptr::null()).expose_addr();
let _ptrs = Simd::<*const i32, 4>::from_exposed_addr(addrs);
let _ptrs = Simd::<*const i32, 4>::with_exposed_provenance(addrs);
}
8 changes: 4 additions & 4 deletions tests/pass/ptr_int_from_exposed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn ptr_roundtrip_out_of_bounds() {

let x_usize = x_ptr.wrapping_offset(128).expose_addr();

let ptr = ptr::from_exposed_addr::<i32>(x_usize).wrapping_offset(-128);
let ptr = ptr::with_exposed_provenance::<i32>(x_usize).wrapping_offset(-128);
assert_eq!(unsafe { *ptr }, 3);
}

Expand All @@ -27,7 +27,7 @@ fn ptr_roundtrip_confusion() {
let x_usize = x_ptr.expose_addr();
let y_usize = y_ptr.expose_addr();

let ptr = ptr::from_exposed_addr::<i32>(y_usize);
let ptr = ptr::with_exposed_provenance::<i32>(y_usize);
let ptr = ptr.with_addr(x_usize);
assert_eq!(unsafe { *ptr }, 0);
}
Expand All @@ -39,7 +39,7 @@ fn ptr_roundtrip_imperfect() {

let x_usize = x_ptr.expose_addr() + 128;

let ptr = ptr::from_exposed_addr::<u8>(x_usize).wrapping_offset(-128);
let ptr = ptr::with_exposed_provenance::<u8>(x_usize).wrapping_offset(-128);
assert_eq!(unsafe { *ptr }, 3);
}

Expand All @@ -51,7 +51,7 @@ fn ptr_roundtrip_null() {
let null = x_null_ptr.expose_addr();
assert_eq!(null, 0);

let x_null_ptr_copy = ptr::from_exposed_addr::<i32>(null); // just a roundtrip, so has provenance of x (angelically)
let x_null_ptr_copy = ptr::with_exposed_provenance::<i32>(null); // just a roundtrip, so has provenance of x (angelically)
let x_ptr_copy = x_null_ptr_copy.with_addr(x_ptr.addr()); // addr of x and provenance of x
assert_eq!(unsafe { *x_ptr_copy }, 42);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pass/stacked-borrows/int-to-ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn example(variant: bool) {
// 4 is the "obvious" choice (topmost tag, what we used to do with untagged pointers).
// And indeed if `variant == true` it is the only possible choice.
// But if `variant == false` then 2 is the only possible choice!
let x_wildcard = ptr::from_exposed_addr_mut::<i32>(x_raw2_addr);
let x_wildcard = ptr::with_exposed_provenance_mut::<i32>(x_raw2_addr);

if variant {
// If we picked 2, this will invalidate 3.
Expand Down
6 changes: 3 additions & 3 deletions tests/pass/stacked-borrows/issue-miri-2389.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ warning: integer-to-pointer cast
LL | let wildcard = &root0 as *const Cell<i32> as usize as *const Cell<i32>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
|
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
= help: This program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`,
= help: which means that Miri might miss pointer bugs in this program.
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
= help: See https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation.
= help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
= help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `with_exposed_provenance` semantics.
= help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
= note: BACKTRACE:
= note: inside `main` at $DIR/issue-miri-2389.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/pass/stacked-borrows/unknown-bottom-gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {

// Expose the allocation and use the exposed pointer, creating an unknown bottom
unsafe {
let p: *mut u8 = ptr::from_exposed_addr::<u8>(ptr.expose_addr()) as *mut u8;
let p: *mut u8 = ptr::with_exposed_provenance::<u8>(ptr.expose_addr()) as *mut u8;
*p = 1;
}

Expand Down

0 comments on commit f2bb429

Please sign in to comment.