Skip to content

Rollup of 10 pull requests #106250

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 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d310292
cargo-miri: use rustc to determine the output filename
RalfJung Dec 27, 2022
ca1e861
Auto merge of #2741 - RalfJung:filenames, r=RalfJung
bors Dec 27, 2022
7bdb5da
handle unknown targets more gracefully
RalfJung Dec 27, 2022
fbdf926
Auto merge of #2742 - RalfJung:targets, r=RalfJung
bors Dec 28, 2022
041ad1f
simplify path joining code a bit
RalfJung Dec 28, 2022
fba3d79
Auto merge of #2743 - RalfJung:path-join, r=RalfJung
bors Dec 28, 2022
874cefa
Powershell: Use `WaitForExit` instead of `-Wait`
ChrisDenton Dec 28, 2022
c3eb202
Migrate scraped examples higlight CSS to variables
GuillaumeGomez Dec 28, 2022
aa20f88
Add GUI test for scraped examples colors
GuillaumeGomez Dec 28, 2022
4fa5192
print sysroot build failure error
RalfJung Dec 28, 2022
fbd6a69
bump dependencies
RalfJung Dec 28, 2022
40d65f0
test using a JSON target file
RalfJung Dec 28, 2022
dfe1898
no need to do a no_std build for wasi
RalfJung Dec 28, 2022
be3ed4f
Auto merge of #2744 - RalfJung:json, r=RalfJung
bors Dec 28, 2022
9221e43
rustdoc: remove unnecessary `.tooltip::after { text-align: center }`
notriddle Dec 28, 2022
9067e44
Rename `Rptr` to `Ref` in AST and HIR
Noratrieb Dec 28, 2022
120d4fd
Remove CraftSpider from review rotation
ehuss Dec 28, 2022
01d7841
Make trait/impl where clause mismatch on region error a bit more acti…
compiler-errors Dec 28, 2022
992ba80
Add test for bad suggestion
compiler-errors Dec 28, 2022
6e794dc
Address review comments
compiler-errors Dec 28, 2022
36e2910
Account for multiple multiline spans with empty padding
estebank Dec 27, 2022
083eb93
On unsized locals with explicit types suggest `&`
estebank Dec 28, 2022
96501bd
Powershell: Create a `Start-Process` wrapper
ChrisDenton Dec 28, 2022
3487fe3
update lockfile
RalfJung Dec 28, 2022
375f025
Detect diff markers in the parser
estebank Dec 29, 2022
38fd5a9
Account for ADT bodies and struct expressions
estebank Dec 29, 2022
698ebe3
Tweak wording
estebank Dec 29, 2022
62c8e31
Add support for diff3 format
estebank Dec 29, 2022
0f86c76
Rollup merge of #106190 - estebank:multiline-start-tweak, r=jackh726
matthiaskrgr Dec 29, 2022
f9fab1f
Rollup merge of #106208 - compiler-errors:compare-item-region-err, r=…
matthiaskrgr Dec 29, 2022
801093f
Rollup merge of #106216 - ChrisDenton:ps-go-faster, r=jyn514
matthiaskrgr Dec 29, 2022
8875ac9
Rollup merge of #106217 - notriddle:notriddle/tooltip-center, r=Guill…
matthiaskrgr Dec 29, 2022
fc5ee6b
Rollup merge of #106218 - GuillaumeGomez:migrate-css-var-scraped-exam…
matthiaskrgr Dec 29, 2022
499055c
Rollup merge of #106221 - Nilstrieb:rptr-more-like-ref-actually, r=co…
matthiaskrgr Dec 29, 2022
77766d5
Rollup merge of #106223 - estebank:suggest-let-ty-borrow, r=compiler-…
matthiaskrgr Dec 29, 2022
58d183e
Rollup merge of #106225 - ehuss:ehuss-patch-1, r=GuillaumeGomez
matthiaskrgr Dec 29, 2022
94dde96
Rollup merge of #106229 - RalfJung:miri, r=RalfJung
matthiaskrgr Dec 29, 2022
160544c
Rollup merge of #106242 - estebank:diff-markers, r=jyn514
matthiaskrgr Dec 29, 2022
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
Prev Previous commit
Next Next commit
handle unknown targets more gracefully
  • Loading branch information
RalfJung committed Dec 28, 2022
commit 7bdb5da91624e027ce38bdabe50d65d5e86bacd0
93 changes: 62 additions & 31 deletions src/tools/miri/src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let min_align = match this.tcx.sess.target.arch.as_ref() {
"x86" | "arm" | "mips" | "powerpc" | "powerpc64" | "asmjs" | "wasm32" => 8,
"x86_64" | "aarch64" | "mips64" | "s390x" | "sparc64" => 16,
arch => bug!("Unsupported target architecture: {}", arch),
arch => bug!("unsupported target architecture for malloc: `{}`", arch),
};
// Windows always aligns, even small allocations.
// Source: <https://support.microsoft.com/en-us/help/286470/how-to-use-pageheap-exe-in-windows-xp-windows-2000-and-windows-server>
Expand Down Expand Up @@ -320,7 +320,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
return Ok(Some(body));
}

this.handle_unsupported(format!("can't call foreign function: {link_name}"))?;
this.handle_unsupported(format!(
"can't call foreign function `{link_name}` on OS `{os}`",
os = this.tcx.sess.target.os,
))?;
return Ok(None);
}
}
Expand All @@ -336,9 +339,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> {
let this = self.eval_context_mut();

let allocator_kind = if let Some(allocator_kind) = this.tcx.allocator_kind(()) {
allocator_kind
} else {
let Some(allocator_kind) = this.tcx.allocator_kind(()) else {
// in real code, this symbol does not exist without an allocator
return Ok(EmulateByNameResult::NotSupported);
};
Expand Down Expand Up @@ -420,9 +421,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?;
let (alloc_id, _, _) = this.ptr_get_alloc_id(ptr).map_err(|_e| {
err_machine_stop!(TerminationInfo::Abort(
format!("pointer passed to miri_get_alloc_id must not be dangling, got {ptr:?}")
))
err_machine_stop!(TerminationInfo::Abort(format!(
"pointer passed to miri_get_alloc_id must not be dangling, got {ptr:?}"
)))
})?;
this.write_scalar(Scalar::from_u64(alloc_id.0.get()), dest)?;
}
Expand All @@ -438,7 +439,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let ptr = this.read_pointer(ptr)?;
let (alloc_id, offset, _) = this.ptr_get_alloc_id(ptr)?;
if offset != Size::ZERO {
throw_unsup_format!("pointer passed to miri_static_root must point to beginning of an allocated block");
throw_unsup_format!(
"pointer passed to miri_static_root must point to beginning of an allocated block"
);
}
this.machine.static_roots.push(alloc_id);
}
Expand All @@ -453,7 +456,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {

// We read this as a plain OsStr and write it as a path, which will convert it to the target.
let path = this.read_os_str_from_c_str(ptr)?.to_owned();
let (success, needed_size) = this.write_path_to_c_str(Path::new(&path), out, out_size)?;
let (success, needed_size) =
this.write_path_to_c_str(Path::new(&path), out, out_size)?;
// Return value: 0 on success, otherwise the size it would have needed.
this.write_int(if success { 0 } else { needed_size }, dest)?;
}
Expand Down Expand Up @@ -505,11 +509,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.write_pointer(res, dest)?;
}
"calloc" => {
let [items, len] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let [items, len] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let items = this.read_machine_usize(items)?;
let len = this.read_machine_usize(len)?;
let size =
items.checked_mul(len).ok_or_else(|| err_ub_format!("overflow during calloc size computation"))?;
let size = items
.checked_mul(len)
.ok_or_else(|| err_ub_format!("overflow during calloc size computation"))?;
let res = this.malloc(size, /*zero_init:*/ true, MiriMemoryKind::C)?;
this.write_pointer(res, dest)?;
}
Expand All @@ -519,7 +525,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.free(ptr, MiriMemoryKind::C)?;
}
"realloc" => {
let [old_ptr, new_size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let [old_ptr, new_size] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let old_ptr = this.read_pointer(old_ptr)?;
let new_size = this.read_machine_usize(new_size)?;
let res = this.realloc(old_ptr, new_size, MiriMemoryKind::C)?;
Expand Down Expand Up @@ -551,11 +558,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
};

match link_name.as_str() {
"__rust_alloc" => return this.emulate_allocator(Symbol::intern("__rg_alloc"), default),
"__rust_alloc" =>
return this.emulate_allocator(Symbol::intern("__rg_alloc"), default),
"miri_alloc" => {
default(this)?;
return Ok(EmulateByNameResult::NeedsJumping);
},
}
_ => unreachable!(),
}
}
Expand All @@ -574,7 +582,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
)?;

// We just allocated this, the access is definitely in-bounds.
this.write_bytes_ptr(ptr.into(), iter::repeat(0u8).take(usize::try_from(size).unwrap())).unwrap();
this.write_bytes_ptr(
ptr.into(),
iter::repeat(0u8).take(usize::try_from(size).unwrap()),
)
.unwrap();
this.write_pointer(ptr, dest)
});
}
Expand All @@ -600,7 +612,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
};

match link_name.as_str() {
"__rust_dealloc" => return this.emulate_allocator(Symbol::intern("__rg_dealloc"), default),
"__rust_dealloc" =>
return this.emulate_allocator(Symbol::intern("__rg_dealloc"), default),
"miri_dealloc" => {
default(this)?;
return Ok(EmulateByNameResult::NeedsJumping);
Expand All @@ -609,7 +622,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}
}
"__rust_realloc" => {
let [ptr, old_size, align, new_size] = this.check_shim(abi, Abi::Rust, link_name, args)?;
let [ptr, old_size, align, new_size] =
this.check_shim(abi, Abi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?;
let old_size = this.read_machine_usize(old_size)?;
let align = this.read_machine_usize(align)?;
Expand All @@ -633,7 +647,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {

// C memory handling functions
"memcmp" => {
let [left, right, n] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let [left, right, n] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let left = this.read_pointer(left)?;
let right = this.read_pointer(right)?;
let n = Size::from_bytes(this.read_machine_usize(n)?);
Expand All @@ -653,7 +668,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.write_scalar(Scalar::from_i32(result), dest)?;
}
"memrchr" => {
let [ptr, val, num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let [ptr, val, num] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?;
let val = this.read_scalar(val)?.to_i32()?;
let num = this.read_machine_usize(num)?;
Expand All @@ -676,7 +692,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}
}
"memchr" => {
let [ptr, val, num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let [ptr, val, num] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?;
let val = this.read_scalar(val)?.to_i32()?;
let num = this.read_machine_usize(num)?;
Expand All @@ -699,7 +716,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let [ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?;
let n = this.read_c_str(ptr)?.len();
this.write_scalar(Scalar::from_machine_usize(u64::try_from(n).unwrap(), this), dest)?;
this.write_scalar(
Scalar::from_machine_usize(u64::try_from(n).unwrap(), this),
dest,
)?;
}

// math functions (note that there are also intrinsics for some other functions)
Expand Down Expand Up @@ -835,7 +855,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let a = this.read_scalar(a)?.to_u64()?;
let b = this.read_scalar(b)?.to_u64()?;

#[allow(clippy::integer_arithmetic)] // adding two u64 and a u8 cannot wrap in a u128
#[allow(clippy::integer_arithmetic)]
// adding two u64 and a u8 cannot wrap in a u128
let wide_sum = u128::from(c_in) + u128::from(a) + u128::from(b);
#[allow(clippy::integer_arithmetic)] // it's a u128, we can shift by 64
let (c_out, sum) = ((wide_sum >> 64).truncate::<u8>(), wide_sum.truncate::<u64>());
Expand All @@ -845,15 +866,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let sum_field = this.place_field(dest, 1)?;
this.write_scalar(Scalar::from_u64(sum), &sum_field)?;
}
"llvm.x86.sse2.pause" if this.tcx.sess.target.arch == "x86" || this.tcx.sess.target.arch == "x86_64" => {
"llvm.x86.sse2.pause"
if this.tcx.sess.target.arch == "x86" || this.tcx.sess.target.arch == "x86_64" =>
{
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
this.yield_active_thread();
}
"llvm.aarch64.isb" if this.tcx.sess.target.arch == "aarch64" => {
let [arg] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?;
let arg = this.read_scalar(arg)?.to_i32()?;
match arg {
15 => { // SY ("full system scope")
// SY ("full system scope")
15 => {
this.yield_active_thread();
}
_ => {
Expand All @@ -863,11 +887,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}

// Platform-specific shims
_ => match this.tcx.sess.target.os.as_ref() {
target if target_os_is_unix(target) => return shims::unix::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
"windows" => return shims::windows::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
target => throw_unsup_format!("the target `{}` is not supported", target),
}
_ =>
return match this.tcx.sess.target.os.as_ref() {
target_os if target_os_is_unix(target_os) =>
shims::unix::foreign_items::EvalContextExt::emulate_foreign_item_by_name(
this, link_name, abi, args, dest,
),
"windows" =>
shims::windows::foreign_items::EvalContextExt::emulate_foreign_item_by_name(
this, link_name, abi, args, dest,
),
_ => Ok(EmulateByNameResult::NotSupported),
},
};
// We only fall through to here if we did *not* hit the `_` arm above,
// i.e., if we actually emulated the function with one of the shims.
Expand Down
9 changes: 2 additions & 7 deletions src/tools/miri/src/shims/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,11 @@ impl TlsDtorsState {
// And move to the final state.
self.0 = Done;
}
"wasi" | "none" => {
// No OS, no TLS dtors.
_ => {
// No TLS dtor support.
// FIXME: should we do something on wasi?
self.0 = Done;
}
os => {
throw_unsup_format!(
"the TLS machinery does not know how to handle OS `{os}`"
);
}
}
}
PthreadDtors(state) => {
Expand Down
14 changes: 7 additions & 7 deletions src/tools/miri/src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
// Platform-specific shims
_ => {
let target_os = &*this.tcx.sess.target.os;
match target_os {
"android" => return shims::unix::android::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
"freebsd" => return shims::unix::freebsd::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
"linux" => return shims::unix::linux::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
"macos" => return shims::unix::macos::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
_ => panic!("unsupported Unix OS {target_os}"),
}
return match target_os {
"android" => shims::unix::android::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
"freebsd" => shims::unix::freebsd::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
"linux" => shims::unix::linux::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
"macos" => shims::unix::macos::foreign_items::EvalContextExt::emulate_foreign_item_by_name(this, link_name, abi, args, dest),
_ => Ok(EmulateByNameResult::NotSupported),
};
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/tools/miri/tests/extern-so/fail/function_not_in_so.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//@only-target-linux
//@only-on-host
//@normalize-stderr-test: "OS `.*`" -> "$$OS"

extern "C" {
fn foo();
}

fn main() {
unsafe {
foo(); //~ ERROR: unsupported operation: can't call foreign function: foo
foo(); //~ ERROR: unsupported operation: can't call foreign function `foo`
}
}
4 changes: 2 additions & 2 deletions src/tools/miri/tests/extern-so/fail/function_not_in_so.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unsupported operation: can't call foreign function: foo
error: unsupported operation: can't call foreign function `foo` on $OS
--> $DIR/function_not_in_so.rs:LL:CC
|
LL | foo();
| ^^^^^ can't call foreign function: foo
| ^^^^^ can't call foreign function `foo` on $OS
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: BACKTRACE:
Expand Down
3 changes: 2 additions & 1 deletion src/tools/miri/tests/fail/alloc/no_global_allocator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@normalize-stderr-test: "OS `.*`" -> "$$OS"
// Make sure we pretend the allocation symbols don't exist when there is no allocator

#![feature(lang_items, start)]
Expand All @@ -10,7 +11,7 @@ extern "Rust" {
#[start]
fn start(_: isize, _: *const *const u8) -> isize {
unsafe {
__rust_alloc(1, 1); //~ERROR: unsupported operation: can't call foreign function: __rust_alloc
__rust_alloc(1, 1); //~ERROR: unsupported operation: can't call foreign function `__rust_alloc`
}

0
Expand Down
4 changes: 2 additions & 2 deletions src/tools/miri/tests/fail/alloc/no_global_allocator.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unsupported operation: can't call foreign function: __rust_alloc
error: unsupported operation: can't call foreign function `__rust_alloc` on $OS
--> $DIR/no_global_allocator.rs:LL:CC
|
LL | __rust_alloc(1, 1);
| ^^^^^^^^^^^^^^^^^^ can't call foreign function: __rust_alloc
| ^^^^^^^^^^^^^^^^^^ can't call foreign function `__rust_alloc` on $OS
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: BACKTRACE:
Expand Down
4 changes: 3 additions & 1 deletion src/tools/miri/tests/fail/unsupported_foreign_function.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//@normalize-stderr-test: "OS `.*`" -> "$$OS"

fn main() {
extern "Rust" {
fn foo();
}

unsafe {
foo(); //~ ERROR: unsupported operation: can't call foreign function: foo
foo(); //~ ERROR: unsupported operation: can't call foreign function `foo`
}
}
4 changes: 2 additions & 2 deletions src/tools/miri/tests/fail/unsupported_foreign_function.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unsupported operation: can't call foreign function: foo
error: unsupported operation: can't call foreign function `foo` on $OS
--> $DIR/unsupported_foreign_function.rs:LL:CC
|
LL | foo();
| ^^^^^ can't call foreign function: foo
| ^^^^^ can't call foreign function `foo` on $OS
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: BACKTRACE:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! `signal()` is special on Linux and macOS that it's only supported within libstd.
//! The implementation is not complete enough to permit user code to call it.
//@ignore-target-windows: No libc on Windows
//@normalize-stderr-test: "OS `.*`" -> "$$OS"

fn main() {
unsafe {
libc::signal(libc::SIGPIPE, libc::SIG_IGN);
//~^ ERROR: unsupported operation: can't call foreign function: signal
//~^ ERROR: unsupported operation: can't call foreign function `signal`
}
}
Loading