about summary refs log tree commit diff
path: root/src/tools/miri
AgeCommit message (Collapse)AuthorLines
2023-12-20Auto merge of #119037 - RalfJung:repr-c-abi-mismatch, r=scottmcmbors-0/+33
do not allow ABI mismatches inside repr(C) types In https://github.com/rust-lang/rust/pull/115476 we allowed ABI mismatches inside `repr(C)` types. This wasn't really discussed much; I added it because from how I understand calling conventions, this should actually be safe in practice. However I entirely forgot to actually allow this in Miri, and in the mean time I have learned that too much ABI compatibility can be a problem for CFI (it can reject fewer calls so that gives an attacker more room to play with). So I propose we take back that part about ABI compatibility in `repr(C)`. It is anyway something that C and C++ do not allow, as far as I understand. In the future we might want to introduce a class of ABI compatibilities where we say "this is a bug and it may lead to aborting the process, but it won't lead to arbitrary misbehavior -- worst case it'll just transmute the arguments from the caller type to the callee type". That would give CFI leeway to reject such calls without introducing the risk of arbitrary UB. (The UB can still happen if the transmute leads to bad results, of course, but it wouldn't be due to ABI weirdness.) #115476 hasn't reached beta yet so if we land this before Dec 22nd we can just pretend this all never happened. ;) Otherwise we should do a beta backport (of the docs change at least). Cc `@rust-lang/opsem` `@rust-lang/types`
2023-12-18Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.Nicholas Nethercote-5/+5
2023-12-18Rename many `EarlyDiagCtxt` arguments.Nicholas Nethercote-4/+4
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-3/+3
2023-12-18Rename `EarlyErrorHandler` as `EarlyDiagCtxt`.Nicholas Nethercote-5/+5
2023-12-17do not allow ABI mismatches inside repr(C) typesRalf Jung-0/+33
2023-12-16Visit the AllocIds and BorTags in borrow state FrameExtraBen Kimock-8/+25
2023-12-15Auto merge of #3226 - saethlin:deadpool-test, r=RalfJungbors-0/+16
Add a regression test for rust#115145 Per https://github.com/rust-lang/rust/pull/118805#issuecomment-1855264860
2023-12-15Add the test minimized from deadpoolBen Kimock-0/+16
2023-12-15Merge from rustcThe Miri Conjob Bot-1/+22
2023-12-15Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2023-12-14Rollup merge of #118933 - nnethercote:cleanup-errors-even-more, ↵Jubilee-1/+1
r=compiler-errors Cleanup errors handlers even more A sequel to #118587. r? `@compiler-errors`
2023-12-15Split `Handler::emit_diagnostic` in two.Nicholas Nethercote-1/+1
Currently, `emit_diagnostic` takes `&mut self`. This commit changes it so `emit_diagnostic` takes `self` and the new `emit_diagnostic_without_consuming` function takes `&mut self`. I find the distinction useful. The former case is much more common, and avoids a bunch of `mut` and `&mut` occurrences. We can also restrict the latter with `pub(crate)` which is nice.
2023-12-14add test for uninhabited saved locals in a coroutineRalf Jung-0/+31
2023-12-14Merge from rustcThe Miri Conjob Bot-1/+44
2023-12-14Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2023-12-13fix computing the dynamic alignment of packed structs with dyn trait tailsRalf Jung-0/+21
2023-12-13Auto merge of #118500 - ZetaNumbers:tcx_hir_refactor, r=petrochenkovbors-1/+1
Move some methods from `tcx.hir()` to `tcx` https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834 Renamed: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id
2023-12-13Auto merge of #118534 - RalfJung:extern-type-size-of-val, r=WaffleLapkinbors-0/+43
codegen: panic when trying to compute size/align of extern type The alignment is also computed when accessing a field of extern type at non-zero offset, so we also panic in that case. Previously `size_of_val` worked because the code path there assumed that "thin pointer" means "sized". But that's not true any more with extern types. The returned size and align are just blatantly wrong, so it seems better to panic than returning wrong results. We use a non-unwinding panic since code probably does not expect size_of_val to panic.
2023-12-12also add a Miri testRalf Jung-0/+43
2023-12-12Move some methods from `tcx.hir()` to `tcx`zetanumbers-1/+1
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
2023-12-12fmtThe Miri Conjob Bot-8/+4
2023-12-12Merge from rustcThe Miri Conjob Bot-19/+12
2023-12-12Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2023-12-11Auto merge of #3222 - RalfJung:waker-noop, r=RalfJungbors-63/+17
tests: use Waker::noop instead of defining our own Waker
2023-12-11use Waker::noop instead of defining our own WakerRalf Jung-63/+17
2023-12-11Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwcobors-0/+2
Add lint against ambiguous wide pointer comparisons This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang. ## `ambiguous_wide_pointer_comparisons` *warn-by-default* The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands. ### Example ```rust let ab = (A, B); let a = &ab.0 as *const dyn T; let b = &ab.1 as *const dyn T; let _ = a == b; ``` ### Explanation The comparison includes metadata which may not be expected. ------- This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one. ~~One thing: is the current naming right? `invalid` seems a bit too much.~~ Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11Auto merge of #118032 - RalfJung:char-u32, r=Mark-Simulacrumbors-1/+5
guarantee that char and u32 are ABI-compatible In https://github.com/rust-lang/rust/pull/116894 we added a guarantee that `char` has the same alignment as `u32`, but there is still one axis where these types could differ: function call ABI. So let's nail that down as well: in a function signature, `char` and `u32` are completely equivalent. This is a new stable guarantee, so it will need t-lang approval.
2023-12-10Auto merge of #3219 - saethlin:map-failed, r=RalfJungbors-4/+83
Return MAP_FAILED when mmap fails I don't properly remember why we ended up with a hodgepodge of return values, but https://github.com/rust-lang/miri/issues/3218 correctly points out that we are supposed to return `MAP_FAILED`. This should fix that return value and also add sufficient tests to prevent making a similar mistake.
2023-12-10Return MAP_FAILED when mmap failsBen Kimock-4/+83
2023-12-10Auto merge of #3199 - Jefffrey:fix-doc-and-script, r=RalfJungbors-3/+4
Fix miri script target dir and update doc link Fix ui_test doc link in `CONTRIBUTING.md` Explicitly set `--target-dir` in `miri` script when building to expected location - I have `build.target-dir` cargo config set to be some other location so miri script was erroring out since compiled binary was not in expected location
2023-12-10Preparing for merge from rustcRalf Jung-1/+1
2023-12-10remove redundant importssurechen-18/+5
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-08Fix x86 SSE4.1 ptestnzcEduardo Sánchez Muñoz-36/+41
`(op & mask) == 0` and `(op & mask) == mask` need each to be calculated for the whole vector. For example, given * `op = [0b100, 0b010]` * `mask = [0b100, 0b110]` The correct result would be: * `op & mask = [0b100, 0b010]` Comparisons are done on the vector as a whole: * `all_zero = (op & mask) == [0, 0] = false` * `masked_set = (op & mask) == mask = false` * `!all_zero && !masked_set = true` The previous method: `op & mask = [0b100, 0b010]` Comparisons are done element-wise: * `all_zero = (op & mask) == [0, 0] = [true, true]` * `masked_set = (op & mask) == mask = [true, false]` * `!all_zero && !masked_set = [true, false]` After folding with AND, the final result would be `false`, which is incorrect.
2023-12-08Auto merge of #3214 - eduardosm:move-x86-code, r=RalfJungbors-265/+304
Move some x86 intrinsics code to helper functions in `shims::x86` To make them reusable for intrinsics of other x86 features. Splitted from https://github.com/rust-lang/miri/pull/3192
2023-12-08Move implementation of SSE4.1 dpps/dppd to helper functionEduardo Sánchez Muñoz-37/+52
2023-12-08Move implementation of SSE4.1 `ptest*` into a helper functionEduardo Sánchez Muñoz-21/+41
2023-12-08Merge from rustcThe Miri Conjob Bot-9/+24
2023-12-08Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2023-12-07Auto merge of #118568 - DianQK:no-builtins-symbols, r=pnkfelixbors-0/+1
Avoid adding builtin functions to `symbols.o` We found performance regressions in #113923. The problem seems to be that `--gc-sections` does not remove these symbols. I tested that lld removes these symbols, but ld and gold do not. I found that `used` adds symbols to `symbols.o` at https://github.com/rust-lang/rust/blob/3e202ead604be31f4c1a5798a296953d3159da7e/compiler/rustc_codegen_ssa/src/back/linker.rs#L1786-L1791. The PR removes builtin functions. Note that under LTO, ld still preserves these symbols. (lld will still remove them.) The first commit also fixes #118559. But I think the second commit also makes sense.
2023-12-07Auto merge of #118324 - RalfJung:ctfe-read-only-pointers, r=saethlinbors-9/+23
compile-time evaluation: detect writes through immutable pointers This has two motivations: - it unblocks https://github.com/rust-lang/rust/pull/116745 (and therefore takes a big step towards `const_mut_refs` stabilization), because we can now detect if the memory that we find in `const` can be interned as "immutable" - it would detect the UB that was uncovered in https://github.com/rust-lang/rust/pull/117905, which was caused by accidental stabilization of `copy` functions in `const` that can only be called with UB When UB is detected, we emit a future-compat warn-by-default lint. This is not a breaking change, so completely in line with [the const-UB RFC](https://rust-lang.github.io/rfcs/3016-const-ub.html), meaning we don't need t-lang FCP here. I made the lint immediately show up for dependencies since it is nearly impossible to even trigger this lint without `const_mut_refs` -- the accidentally stabilized `copy` functions are the only way this can happen, so the crates that popped up in #117905 are the only causes of such UB (in the code that crater covers), and the three cases of UB that we know about have all been fixed in their respective crates already. The way this is implemented is by making use of the fact that our interpreter is already generic over the notion of provenance. For CTFE we now use the new `CtfeProvenance` type which is conceptually an `AllocId` plus a boolean `immutable` flag (but packed for a more efficient representation). This means we can mark a pointer as immutable when it is created as a shared reference. The flag will be propagated to all pointers derived from this one. We can then check the immutable flag on each write to reject writes through immutable pointers. I just hope perf works out.
2023-12-07also print 'immutable' flagRalf Jung-0/+11
2023-12-07compile-time evaluation: emit a lint when a write through an immutable ↵Ralf Jung-3/+4
pointer occurs
2023-12-07ctfe interpreter: extend provenance so that it can track whether a pointer ↵Ralf Jung-6/+8
is immutable
2023-12-07Move round_* functions from `shims::x86::sse41` module to `shims::x86`Eduardo Sánchez Muñoz-84/+84
2023-12-07Move unary_op_* functions from `shims::x86::sse` module to `shims::x86`Eduardo Sánchez Muñoz-125/+129
2023-12-06Adjust tests for newly added ambiguous_wide_pointer_comparisons lintUrgau-0/+2
2023-12-05remove unnecesary `-Zunstable-options`Weihang Lo-4/+1
AFAIK `-Zunstable-options` is for `cargo --config` CLI, which was stabilized in 1.63 https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#config-cli
2023-12-05Fix formattingIgor Matuszewski-1/+3
2023-12-05Don't explicitly warn against `semicolon_in_expressions_from_macros`Igor Matuszewski-1/+1
This warns-by-default since 2 years and already has been added to the future-incompat group since Rust 1.68. See https://github.com/rust-lang/rust/issues/79813 for the tracking issue.