summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/interpret
AgeCommit message (Collapse)AuthorLines
2024-08-31Rollup merge of #129684 - Strophox:miri-pass-pointer-to-ffi, r=RalfJungMatthias Krüger-1/+2
Enable Miri to pass pointers through FFI Following https://github.com/rust-lang/rust/pull/126787, the purpose of this PR is to now enable Miri to execute native calls that make use of pointers. > <details> > > <summary> Simple example </summary> > > ```rust > extern "C" { > fn ptr_printer(ptr: *mut i32); > } > > fn main() { > let ptr = &mut 42 as *mut i32; > unsafe { > ptr_printer(ptr); > } > } > ``` > ```c > void ptr_printer(int *ptr) { > printf("printing pointer dereference from C: %d\n", *ptr); > } > ``` > should now show `printing pointer dereference from C: 42`. > > </details> Note that this PR does not yet implement any logic involved in updating Miri's "analysis" state (byte initialization, provenance) upon such a native call. r? ``@RalfJung``
2024-08-30enable Miri to pass const pointers through FFIStrophox-1/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-08-29Add `warn(unreachable_pub)` to `rustc_middle`.Nicholas Nethercote-1/+1
I am surprised the diff is so small for this enormous crate.
2024-08-14use the new Box methods in the interpreterRalf Jung-4/+2
2024-08-06miri: make vtable addresses not globally uniqueRalf Jung-94/+51
2024-08-01interpret: simplify pointer arithmetic logicRalf Jung-88/+12
2024-08-01on a signed deref check, mention the right pointer in the errorRalf Jung-9/+7
2024-07-29Rollup merge of #128277 - RalfJung:offset_from_wildcard, r=oli-obkMatthias Krüger-6/+14
miri: fix offset_from behavior on wildcard pointers offset_from wouldn't behave correctly when the "end" pointer was a wildcard pointer (result of an int2ptr cast) just at the end of the allocation. Fix that by expressing the "same allocation" check in terms of two `check_ptr_access_signed` instead of something specific to offset_from, which is both more canonical and works better with wildcard pointers. The second commit just improves diagnostics: I wanted the "pointer is dangling (has no provenance)" message to say how many bytes of memory it expected to see (since if it were 0 bytes, this would actually be legal, so it's good to tell the user that it's not 0 bytes). And then I was annoying that the error looks so different for when you deref a dangling pointer vs an out-of-bounds pointer so I made them more similar. Fixes https://github.com/rust-lang/miri/issues/3767
2024-07-29Reformat `use` declarations.Nicholas Nethercote-54/+39
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-27improve dangling/oob errors and make them more uniformRalf Jung-6/+14
2024-07-22Auto merge of #127442 - saethlin:alloc-decoding-lock, r=oli-obkbors-89/+25
Try to fix ICE from re-interning an AllocId with different allocation contents As far as I can tell, based on my investigation in https://github.com/rust-lang/rust/issues/126741, the racy decoding scheme implemented here was never fully correct, but the arrangement of Allocations that's required to ICE the compiler requires some very specific MIR optimizations to create. As far as I can tell, GVN likes to create the problematic pattern, which is why we're noticing this problem now. So the solution here is to not do racy decoding. If two threads race to decoding an AllocId, one of them is going to sit on a lock until the other is done.
2024-07-21Explain why the new setup can't deadlockBen Kimock-1/+13
2024-07-18valtree construction: keep track of which type was valtree-incompatibleRalf Jung-3/+5
2024-07-17Remove in-progress allocation decoding statesBen Kimock-89/+13
2024-07-14Add cache for `allocate_str`Adwin White-6/+11
2024-07-04Auto merge of #123781 - RalfJung:miri-fn-identity, r=oli-obkbors-23/+50
Miri function identity hack: account for possible inlining Having a non-lifetime generic is not the only reason a function can be duplicated. Another possibility is that the function may be eligible for cross-crate inlining. So also take into account the inlining attribute in this Miri hack for function pointer identity. That said, `cross_crate_inlinable` will still sometimes return true even for `inline(never)` functions: - when they are `DefKind::Ctor(..) | DefKind::Closure` -- I assume those cannot be `InlineAttr::Never` anyway? - when `cross_crate_inline_threshold == InliningThreshold::Always` so maybe this is still not quite the right criterion to use for function pointer identity.
2024-07-02Instance::resolve -> Instance::try_resolve, and other nitsMichael Goulet-2/+2
2024-07-02Miri function identity hack: account for possible inliningRalf Jung-23/+50
2024-06-22don't ICE when encountering an extern type field during validationRalf Jung-0/+2
2024-06-21add as_ptr to trait AllocBytes, fix 2 impls; add pub fn ↵Strophox-3/+23
get_bytes_unchecked_raw in allocation.rs; add pub fn get_alloc_bytes_unchecked_raw[_mut] in memory.rs
2024-06-18Rollup merge of #126583 - RalfJung:interpret-oom, r=saethlinGuillaume Gomez-2/+5
interpret: better error when we ran out of memory
2024-06-17Remove an unused validation error variantOli Scherer-3/+0
2024-06-17interpret: better error when we ran out of memoryRalf Jung-2/+5
2024-06-14Enable const evaluation for `f16` and `f128`Trevor Gross-0/+14
This excludes casting, which needs more tests.
2024-06-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-24/+9
2024-06-08add missing Scalar::from_i128Ralf Jung-0/+5
2024-06-05Don't walk the bodies of free constants for reachability.Oli Scherer-3/+23
2024-05-27miri: avoid making a full copy of all new allocationsRalf Jung-22/+21
2024-05-27Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercotebors-2/+1
[perf] Delay the construction of early lint diag structs Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666. See individual commits for details. The first three commits are not strictly necessary. However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement. It's also pretty sweet on its own if I may say so myself.
2024-05-23Auto merge of #125434 - nnethercote:rm-more-extern-tracing, r=jackh726bors-3/+5
Remove more `#[macro_use] extern crate tracing` Because explicit importing of macros via use items is nicer (more standard and readable) than implicit importing via `#[macro_use]`. Continuing the work from #124511 and #124914. r? `@jackh726`
2024-05-23Allow const eval failures if the cause is a type layout issueOli Scherer-0/+3
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_middle`.Nicholas Nethercote-3/+5
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-2/+1
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-21interpret: make overflowing binops just normal binopsRalf Jung-6/+13
2024-05-13interpret: move error macros into error.rsRalf Jung-132/+126
2024-05-13Remove `extern crate rustc_middle` from `rustc_const_eval`.Nicholas Nethercote-11/+27
This requires exporting the interpreter macros so they can be used with `use crate::interpret::*`.
2024-05-09Remove `TinyList`.Nicholas Nethercote-9/+8
It is optimized for lists with a single element, avoiding the need for an allocation in that case. But `SmallVec<[T; 1]>` also avoids the allocation, and is better in general: more standard, log2 number of allocations if the list exceeds one item, and a much more capable API. This commit removes `TinyList` and converts the two uses to `SmallVec<[T; 1]>`. It also reorders the `use` items in the relevant file so they are in just two sections (`pub` and non-`pub`), ordered alphabetically, instead of many sections. (This is a relevant part of the change because I had to decide where to add a `use` item for `SmallVec`.)
2024-05-03remove trait bounds on AllocBytesStrophox-3/+1
2024-05-03Cow::from(&*...) changed to Cow::Owned(Vec::from(...))Strophox-1/+1
2024-05-03generalize adjust_from_tcxStrophox-4/+4
2024-04-29Remove `extern crate rustc_data_structures` from numerous crates.Nicholas Nethercote-2/+3
2024-04-29Remove `extern crate rustc_macros` from `rustc_middle`.Nicholas Nethercote-4/+7
2024-04-21Miri: detect wrong vtables in wide pointersRalf Jung-21/+78
2024-04-19Auto merge of #124113 - RalfJung:interpret-scalar-ops, r=oli-obkbors-11/+13
interpret: use ScalarInt for bin-ops; avoid PartialOrd for ScalarInt Best reviewed commit-by-commit r? `@oli-obk`
2024-04-19ScalarInt: add methods to assert being a (u)int of given sizeRalf Jung-2/+2
2024-04-18interpret/binary_int_op: avoid dropping to raw ints until we determined the signRalf Jung-10/+12
2024-04-18Simplify `static_assert_size`s.Nicholas Nethercote-2/+2
We want to run them on all 64-bit platforms.
2024-04-03Check `x86_64` size assertions on `aarch64`, tooZalathar-2/+2
This makes it easier for contributors on aarch64 workstations (e.g. Macs) to notice when these assertions have been violated.
2024-03-26Auto merge of #111769 - saethlin:ctfe-backtrace-ctrlc, r=RalfJungbors-0/+2
Print a backtrace in const eval if interrupted Demo: ```rust #![feature(const_eval_limit)] #![const_eval_limit = "0"] const OW: u64 = { let mut res: u64 = 0; let mut i = 0; while i < u64::MAX { res = res.wrapping_add(i); i += 1; } res }; fn main() { println!("{}", OW); } ``` ``` ╭ ➜ ben@archlinux:~/rust ╰ ➤ rustc +stage1 spin.rs ^Cerror[E0080]: evaluation of constant value failed --> spin.rs:8:33 | 8 | res = res.wrapping_add(i); | ^ Compilation was interrupted note: erroneous constant used --> spin.rs:15:20 | 15 | println!("{}", OW); | ^^ note: erroneous constant used --> spin.rs:15:20 | 15 | println!("{}", OW); | ^^ | = note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error For more information about this error, try `rustc --explain E0080`. ```
2024-03-22Rollup merge of #122537 - RalfJung:interpret-allocation, r=oli-obkMatthias Krüger-11/+31
interpret/allocation: fix aliasing issue in interpreter and refactor getters a bit That new raw getter will be needed to let Miri pass pointers to natively executed FFI code ("extern-so" mode). While doing that I realized our get_bytes_mut are named less scary than get_bytes_unchecked so I rectified that. Also I realized `mem_copy_repeatedly` would break if we called it for multiple overlapping copies so I made sure this does not happen. And I realized that we are actually [violating Stacked Borrows in the interpreter](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/I.20think.20Miri.20violates.20Stacked.20Borrows.20.F0.9F.99.88).^^ That was introduced in https://github.com/rust-lang/rust/pull/87777. r? ```@oli-obk```