about summary refs log tree commit diff
path: root/src/tools/miri/tests
AgeCommit message (Collapse)AuthorLines
2025-08-20make `prefetch` intrinsics safeFolkert de Vries-14/+14
2025-08-19add a fallback implementation for the `prefetch_*` intrinsicsFolkert de Vries-0/+23
The fallback is to just ignore the arguments. That is a valid implementation because this intrinsic is just a hint. I also added `miri::intrinsic_fallback_is_spec` annotation, so that miri now supports these operations. A prefetch intrinsic call is valid on any pointer.
2025-08-19Rollup merge of #145585 - RalfJung:miri-inplace-arg-checks, r=compiler-errors许杰友 Jieyou Xu (Joe)-37/+129
Miri: fix handling of in-place argument and return place handling This fixes two separate bugs (in two separate commits): - If the return place is `_local` and not `*ptr`, we didn't always properly protect it if there were other pointers pointing to that return place. - If two in-place arguments are *the same* local variable, we didn't always detect that aliasing.
2025-08-19miri: detect passing the same local twice as an in-place argumentRalf Jung-0/+92
2025-08-18interpret: fix in-place return place semantics when the return place ↵Ralf Jung-37/+37
expression is a local variable
2025-08-17Auto merge of #144081 - RalfJung:const-ptr-fragments, r=oli-obkbors-63/+98
const-eval: full support for pointer fragments This fixes https://github.com/rust-lang/const-eval/issues/72 and makes `swap_nonoverlapping` fully work in const-eval by enhancing per-byte provenance tracking with tracking of *which* of the bytes of the pointer this one is. Later, if we see all the same bytes in the exact same order, we can treat it like a whole pointer again without ever risking a leak of the data bytes (that encode the offset into the allocation). This lifts the limitation that was discussed quite a bit in https://github.com/rust-lang/rust/pull/137280. For a concrete piece of code that used to fail and now works properly consider this example doing a byte-for-byte memcpy in const without using intrinsics: ```rust use std::{mem::{self, MaybeUninit}, ptr}; type Byte = MaybeUninit<u8>; const unsafe fn memcpy(dst: *mut Byte, src: *const Byte, n: usize) { let mut i = 0; while i < n { *dst.add(i) = *src.add(i); i += 1; } } const _MEMCPY: () = unsafe { let ptr = &42; let mut ptr2 = ptr::null::<i32>(); // Copy from ptr to ptr2. memcpy(&mut ptr2 as *mut _ as *mut _, &ptr as *const _ as *const _, mem::size_of::<&i32>()); assert!(*ptr2 == 42); }; ``` What makes this code tricky is that pointers are "opaque blobs" in const-eval, we cannot just let people look at the individual bytes since *we don't know what those bytes look like* -- that depends on the absolute address the pointed-to object will be placed at. The code above "breaks apart" a pointer into individual bytes, and then puts them back together in the same order elsewhere. This PR implements the logic to properly track how those individual bytes relate to the original pointer, and to recognize when they are in the right order again. We still reject constants where the final value contains a not-fully-put-together pointer: I have no idea how one could construct an LLVM global where one byte is defined as "the 3rd byte of a pointer to that other global over there" -- and even if LLVM supports this somehow, we can leave implementing that to a future PR. It seems unlikely to me anyone would even want this, but who knows.^^ This also changes the behavior of Miri, by tracking the order of bytes with provenance and only considering a pointer to have valid provenance if all bytes are in the original order again. This is related to https://github.com/rust-lang/unsafe-code-guidelines/issues/558. It means one cannot implement XOR linked lists with strict provenance any more, which is however only of theoretical interest. Practically I am curious if anyone will show up with any code that Miri now complains about - that would be interesting data. Cc `@rust-lang/opsem`
2025-08-08Auto merge of #145126 - tgross35:rollup-6w87usd, r=tgross35bors-1/+1
Rollup of 8 pull requests Successful merges: - rust-lang/rust#139451 (Add `target_env = "macabi"` and `target_env = "sim"`) - rust-lang/rust#144039 (Use `tcx.short_string()` in more diagnostics) - rust-lang/rust#144192 (atomicrmw on pointers: move integer-pointer cast hacks into backend) - rust-lang/rust#144545 (In rustc_pattern_analysis, put `true` witnesses before `false` witnesses) - rust-lang/rust#144579 (Implement declarative (`macro_rules!`) attribute macros (RFC 3697)) - rust-lang/rust#144649 (Account for bare tuples and `Pin` methods in field searching logic) - rust-lang/rust#144775 (more strongly dissuade use of `skip_binder`) - rust-lang/rust#144987 (Enable f16 and f128 on targets that were fixed in LLVM21) r? `@ghost` `@rustbot` modify labels: rollup
2025-08-08Rollup merge of #144579 - joshtriplett:mbe-attr, r=petrochenkovTrevor Gross-1/+1
Implement declarative (`macro_rules!`) attribute macros (RFC 3697) This implements [RFC 3697](https://github.com/rust-lang/rust/issues/143547), "Declarative (`macro_rules!`) attribute macros". I would suggest reading this commit-by-commit. This first introduces the feature gate, then adds parsing for attribute rules (doing nothing with them), then adds the ability to look up and apply `macro_rules!` attributes by path, then adds support for local attributes, then adds a test, and finally makes various improvements to errors.
2025-08-08mbe: In error messages, don't assume attributes are always proc macrosJosh Triplett-1/+1
Now that `macro_rules` macros can define attribute rules, make sure error messages account for that.
2025-08-08Revert "Rollup merge of #143906 - ↵Jakub Beránek-110/+44
LorrensP-2158466:miri-float-nondet-foreign-items, r=RalfJung" This reverts commit 71f04692c32e181ab566c01942f1418dec8662d4, reversing changes made to 995ca3e532b48b689567533e6b736675e38b741e.
2025-08-07Rollup merge of #144903 - Kivooeo:panic_handler-is-not-begin, r=m-ou-seTrevor Gross-23/+23
Rename `begin_panic_handler` to `panic_handler` Part of https://github.com/rust-lang/rust/issues/116005
2025-08-07Rollup merge of #143906 - LorrensP-2158466:miri-float-nondet-foreign-items, ↵Stuart Cook-44/+110
r=RalfJung Miri: non-deterministic floating point operations in `foreign_items` Part of [rust-lang/miri/#3555](https://github.com/rust-lang/miri/issues/3555#issue-2278914000), this pr does the `foreign_items` work. Some things have changed since rust-lang/rust#138062 and rust-lang/rust#142514. I moved the "helpers" used for creating fixed outputs and clamping operations to their defined ranges to `math.rs`. These are now also extended to handle the floating-point operations in `foreign_items`. Tests in `miri/tests/float.rs` were changed/added. Failing tests in `std` were extracted, run under miri with `-Zmiri-many-seeds=0..1000` and changed accordingly. Double checked with `-Zmiri-many-seeds`. I noticed that the C standard doesn't specify the output ranges for all of its mathematical operations; it just specifies them as: ``` Returns The sinh functions return sinh x. ``` So I used [Wolfram|Alpha](https://www.wolframalpha.com/).
2025-08-06Print thread ID in panic message if thread name is unknownTrevor Gross-57/+63
`panic!` does not print any identifying information for threads that are unnamed. However, in many cases, the thread ID can be determined. This changes the panic message from something like this: thread '<unnamed>' panicked at src/main.rs:3:5: explicit panic To something like this: thread '<unnamed>' (0xff9bf) panicked at src/main.rs:3:5: explicit panic Stack overflow messages are updated as well. This change applies to both named and unnamed threads. The ID printed is the OS integer thread ID rather than the Rust thread ID, which should also be what debuggers print.
2025-08-06Add normalization for thread IDs in panic messagesTrevor Gross-1/+2
So we don't need to add normalization to every test that includes a panic message, add a global normalization to compiletest.
2025-08-04remove begin prefixKivooeo-23/+23
2025-08-04Rollup merge of #144853 - Kivooeo:rust_-cleanup, r=Mark-SimulacrumStuart Cook-11/+11
Remove unnecessary `rust_` prefixes part of https://github.com/rust-lang/rust/issues/116005 Honestly, not sure if this can affect linking somehow, also I didn't touched things like `__rust_panic_cleanup` and `__rust_start_panic` which very likely will break something, so just small cleanup here also didn't changed `rust_panic_without_hook` because it was renamed here https://github.com/rust-lang/rust/pull/144852 r? libs
2025-08-04Rollup merge of #144706 - zachs18:fix-144661, r=RalfJungStuart Cook-25/+0
Do not give function allocations alignment in consteval and Miri. We do not yet have a (clear and T-lang approved) design for how `#[align(N)]` on functions should affect function pointers' addresses on various platforms, so for now do not give function pointers alignment in consteval and Miri. ---- Old summary: Not a full solution to <https://github.com/rust-lang/rust/issues/144661>, but fixes the immediate issue by making function allocations all have alignment 1 in consteval, ignoring `#[rustc_align(N)]`, so the compiler doesn't know if any offset other than 0 is non-null. A more "principlied" solution would probably be to make function pointers to `#[instruction_set(arm::t32)]` functions be at offset 1 of an align-`max(2, align attribute)` allocation instead of at offset 0 of their allocation during consteval, and on wasm to either disallow `#[align(N)]` where N > 1, or to pad the function table such that the function pointer of a `#[align(N)]` function is a multiple of `N` at runtime.
2025-08-03remove rust_ prefixesKivooeo-11/+11
2025-07-31Allow `dangling_pointers_from_locals` lint in testsUrgau-0/+3
2025-07-31Do not give function allocations alignment in consteval or miri.Zachary S-25/+0
2025-07-30const-eval: full support for pointer fragmentsRalf Jung-63/+98
2025-07-28lookup_link_section: support arrays of function pointersRalf Jung-8/+7
2025-07-28revert accidental changeRalf Jung-0/+4
2025-07-28Merge commit 'abd9cba5acbcc35fb4cc59ce25580fa1624b5571'Ralf Jung-21/+17
2025-07-27miri: for ABI mismatch errors, say which argument is the problemRalf Jung-21/+17
2025-07-27Merge pull request #4498 from RalfJung/genmc-buildRalf Jung-0/+27
Add support for building and linking against genmc
2025-07-27various minor adjustmentsRalf Jung-2/+1
2025-07-27Add support for building and linking against genmcPatrick-6-0/+28
2025-07-27call_function helper: dont ICE on return type mismatchesRalf Jung-0/+51
2025-07-25fix target jsonRalf Jung-1/+1
2025-07-25Merge ref 'b56aaec52bc0' from rust-lang/rustThe Miri Cronjob Bot-13/+7
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: b56aaec52bc0fa35591a872fb4aac81f606e265c Filtered ref: 12f5e3255df658296af9fc953d8c1ab79ba91ea3 This merge was created using https://github.com/rust-lang/josh-sync.
2025-07-23Remove const deduplication from the interpreter.Camille GILLOT-13/+7
2025-07-22Merge from rustcThe Miri Cronjob Bot-11/+21
2025-07-21Implement nondet behaviour and change/add tests.LorrensP-2158466-44/+110
2025-07-22Rollup merge of #144080 - jieyouxu:realign, r=BoxyUwU许杰友 Jieyou Xu (Joe)-3/+7
Mitigate `#[align]` name resolution ambiguity regression with a rename Mitigates beta regression rust-lang/rust#143834 after a beta backport. ### Background on the beta regression The name resolution regression arises due to rust-lang/rust#142507 adding a new feature-gated built-in attribute named `#[align]`. However, unfortunately even [introducing new feature-gated unstable built-in attributes can break user code](https://www.github.com/rust-lang/rust/issues/134963) such as ```rs macro_rules! align { () => { /* .. */ }; } pub(crate) use align; // `use` here becomes ambiguous ``` ### Mitigation approach This PR renames `#[align]` to `#[rustc_align]` to mitigate the beta regression by: 1. Undoing the introduction of a new built-in attribute with a common name, i.e. `#[align]`. 2. Renaming `#[align]` to `#[rustc_align]`. The renamed attribute being `rustc_align` will not introduce new stable breakages, as attributes beginning with `rustc` are reserved and perma-unstable. This does mean existing nightly code using `fn_align` feature will additionally need to specify `#![feature(rustc_attrs)]`. This PR is very much a short-term mitigation to alleviate time pressure from having to fully fix the current limitation of inevitable name resolution regressions that would arise from adding any built-in attributes. Long-term solutions are discussed in [#t-lang > namespacing macro attrs to reduce conflicts with new adds](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/namespacing.20macro.20attrs.20to.20reduce.20conflicts.20with.20new.20adds/with/529249622). ### Alternative mitigation options [Various mitigation options were considered during the compiler triage meeting](https://github.com/rust-lang/rust/issues/143834#issuecomment-3084415277), and those consideration are partly reproduced here: - Reverting the PR doesn't seem very minimal/trivial, and carries risks of its own. - Rename to a less-common but aim-to-stabilization name is itself not safe nor convenient, because (1) that risks introducing new regressions (i.e. ambiguity against the new name), and (2) lang would have to FCP the new name hastily for the mitigation to land timely and have a chance to be backported. This also makes the path towards stabilization annoying. - Rename the attribute to a rustc attribute, which will be perma-unstable and does not cause new ambiguities in stable code. - This alleviates the time pressure to address *this* regression, or for lang to have to rush an FCP for some new name that can still break user code. - This avoids backing out a whole implementation. ### Review advice This PR is best reviewed commit-by-commit. - Commit 1 adds a test `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` which demonstrates the current name resolution regression re. `align`. This test fails against current master. - Commit 2 carries out the renames and test reblesses. Notably, commit 2 will cause `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` to change from fail (nameres regression) to pass. This PR, if the approach still seems acceptable, will need a beta-backport to address the beta regression.
2025-07-21Merge pull request #4481 from RalfJung/read-write-truncateOli Scherer-112/+273
non-deterministically truncate reads/writes
2025-07-21Auto merge of #144238 - jhpratt:rollup-xb8aida, r=jhprattbors-7/+679
Rollup of 8 pull requests Successful merges: - rust-lang/rust#144144 (tests: Skip supported-crate-types test on musl hosts) - rust-lang/rust#144159 (opt-dist: change build_dir field to be an actual build dir) - rust-lang/rust#144162 (Debug impls for DropElaborators) - rust-lang/rust#144189 (Add non-regression test for rust-lang/rust#144168) - rust-lang/rust#144216 (Don't consider unstable fields always-inhabited) - rust-lang/rust#144229 (Miri subtree update) - rust-lang/rust#144230 (Option::as_slice: fix comment) - rust-lang/rust#144235 (Fix run-make tests on musl hosts) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-21Merge from rustcThe Miri Cronjob Bot-4/+29
2025-07-20Rollup merge of #144229 - RalfJung:miri-sync, r=RalfJungJacob Pratt-7/+679
Miri subtree update r? `@ghost`
2025-07-20Update Miri TestsScott McMurray-8/+14
2025-07-20Rollup merge of #144190 - scottmcm:spanned-errors-in-mir-validation, r=RalfJungGuillaume Gomez-4/+10
Give a message with a span on MIR validation error It was handy to get a source+line link for rust-lang/rust#143833, even if it's just to the function and not necessarily to the statement. r? mir
2025-07-20Rollup merge of #144169 - RalfJung:type-id-fix, r=oli-obkMatthias Krüger-0/+19
interpret: fix TypeId pointers being considered data pointers Fixes https://github.com/rust-lang/miri/issues/4477 r? ````@oli-obk````
2025-07-20Merge from rustcThe Miri Cronjob Bot-34/+155
2025-07-19Give a message with a span on validation errorScott McMurray-4/+10
2025-07-19non-deterministically truncate reads/writesRalf Jung-112/+269
2025-07-19don't halt execution when we write to a read-only fileRalf Jung-0/+4
2025-07-19move and update test dependenciesRalf Jung-1/+675
2025-07-19bump ui_testRalf Jung-5/+3
2025-07-19Auto merge of #144166 - matthiaskrgr:rollup-wccepuo, r=matthiaskrgrbors-3/+3
Rollup of 10 pull requests Successful merges: - rust-lang/rust#141076 (fix Zip unsoundness (again)) - rust-lang/rust#142444 (adding run-make test to autodiff) - rust-lang/rust#143704 (Be a bit more careful around exotic cycles in in the inliner) - rust-lang/rust#144073 (Don't test panic=unwind in panic_main.rs on Fuchsia) - rust-lang/rust#144083 (miri sleep tests: increase slack) - rust-lang/rust#144092 (bootstrap: Detect musl hosts) - rust-lang/rust#144098 (Do not lint private-in-public for RPITIT) - rust-lang/rust#144103 (Rename `emit_unless` to `emit_unless_delay`) - rust-lang/rust#144108 (Ignore tests/run-make/link-eh-frame-terminator/rmake.rs when cross-compiling) - rust-lang/rust#144115 (fix outdated comment) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-19interpret: fix TypeId pointers being considered data pointersRalf Jung-0/+19