rust/compiler/rustc_const_eval/src
Matthias Krüger 576176d8b7
Rollup merge of #133211 - Strophox:miri-correct-state-update-ffi, r=RalfJung
Extend Miri to correctly pass mutable pointers through FFI

Based off of https://github.com/rust-lang/rust/pull/129684, this PR further extends Miri to execute native calls that make use of pointers to *mutable* memory.
We adapt Miri's bookkeeping of internal state upon any FFI call that gives external code permission to mutate memory.

Native code may now possibly write and therefore initialize and change the pointer provenance of bytes it has access to: Such memory is assumed to be *initialized* afterwards and bytes are given *arbitrary (wildcard) provenance*. This enables programs that correctly use mutating FFI calls to run Miri without errors, at the cost of possibly missing Undefined Behaviour caused by incorrect usage of mutating FFI.

> <details>
>
> <summary> Simple example </summary>
>
> ```rust
> extern "C" {
>   fn init_int(ptr: *mut i32);
> }
>
> fn main() {
>   let mut x = std::mem::MaybeUninit::<i32>::uninit();
>   let x = unsafe {
>     init_int(x.as_mut_ptr());
>     x.assume_init()
>   };
>
>   println!("C initialized my memory to: {x}");
> }
> ```
> ```c
> void init_int(int *ptr) {
>   *ptr = 42;
> }
> ```
> should now show `C initialized my memory to: 42`.
>
> </details>

r? ``@RalfJung``
2024-12-06 09:27:39 +01:00
..
check_consts Auto merge of #133321 - compiler-errors:const-checker, r=wesleywiser 2024-12-03 04:39:48 +00:00
const_eval Rollup merge of #133211 - Strophox:miri-correct-state-update-ffi, r=RalfJung 2024-12-06 09:27:39 +01:00
interpret Rollup merge of #133211 - Strophox:miri-correct-state-update-ffi, r=RalfJung 2024-12-06 09:27:39 +01:00
util InterpCx store TypingEnv instead of a ParamEnv 2024-11-19 21:36:23 +01:00
errors.rs Deduplicate checking drop terminator 2024-11-22 16:54:41 +00:00
lib.rs report UB when the niche value refers to the untagged variant 2024-11-30 18:26:30 +01:00