Files
rust/compiler/rustc_const_eval
Jonathan Brouwer 8b9c125b70 Rollup merge of #161734 - RalfJung:c-variadic-types, r=oli-obk
miri: enforce proper types for c-variadic arguments in shims

This adds proper type checks for c-variadic argument handling in Miri shims. So far we would have ICEd for many type mismatches since the innards of the interpreter generally assume that things are well-typed. The checks we are using are the same as for [`next_arg`](https://doc.rust-lang.org/nightly/std/ffi/struct.VaList.html#method.next_arg).

This uncovered some interesting points:
-  We should accept `&mut` as equivalent to `*mut`. We don't allow `&mut` as a type in `next_arg` but we do allow it for c-variadic calls, so this change also affects a bit more code in const-eval (if the caller passes an `&mut` and the callee expects a `*mut`). Even CFI is okay with treating `&mut` and `*mut` as equivalent so this should be fine. Cc @folkertdev
- Some places in the standard library futex handling used types for their variadic arguments that are not quite correct according to these rules. I fixed those. Cc @m-ou-se
- One variadic function takes pointers to `libc::timespec`. A program with a libc dependency has two copies of libc (one in the sysroot, and the normal dependency). When Miri looks up the expected argument type, it picks one of them, leading to Miri seeing a type mismatch when there is a call using the other copy. C generally considers two copies of the same type to be identical, so I implemented logic that does the same: two `repr(C)` types are "identical" if the names of the types, and the names and types of all fields, are identical. I then also used that logic for the normal ABI checks, where it will also help since we had similar trouble there in the past (that we had to find other work-arounds for).
2026-09-09 15:01:28 +02:00
..
2026-08-21 10:33:56 +02:00