Commit graph

2542 commits

Author SHA1 Message Date
León Orell Valerian Liehr
76d4bfb1c6
Rollup merge of #124896 - RalfJung:miri-intrinsic-fallback, r=oli-obk
miri: rename intrinsic_fallback_checks_ub to intrinsic_fallback_is_spec

Checking UB is not the only concern, we also have to make sure we are not losing out on non-determinism.

r? ``@oli-obk`` (not urgent, take your time)
2024-05-22 19:04:43 +02:00
bors
5d328a1f62 Auto merge of #117329 - RalfJung:offset-by-zero, r=oli-obk,scottmcm
offset: allow zero-byte offset on arbitrary pointers

As per prior `@rust-lang/opsem` [discussion](https://github.com/rust-lang/opsem-team/issues/10) and [FCP](https://github.com/rust-lang/unsafe-code-guidelines/issues/472#issuecomment-1793409130):

- Zero-sized reads and writes are allowed on all sufficiently aligned pointers, including the null pointer
- Inbounds-offset-by-zero is allowed on all pointers, including the null pointer
- `offset_from` on two pointers derived from the same allocation is always allowed when they have the same address

This removes surprising UB (in particular, even C++ allows "nullptr + 0", which we currently disallow), and it brings us one step closer to an important theoretical property for our semantics ("provenance monotonicity": if operations are valid on bytes without provenance, then adding provenance can't make them invalid).

The minimum LLVM we require (v17) includes https://reviews.llvm.org/D154051, so we can finally implement this.

The `offset_from` change is needed to maintain the equivalence with `offset`: if `let ptr2 = ptr1.offset(N)` is well-defined, then `ptr2.offset_from(ptr1)` should be well-defined and return N. Now consider the case where N is 0 and `ptr1` dangles: we want to still allow offset_from here.

I think we should change offset_from further, but that's a separate discussion.

Fixes https://github.com/rust-lang/rust/issues/65108
[Tracking issue](https://github.com/rust-lang/rust/issues/117945) | [T-lang summary](https://github.com/rust-lang/rust/pull/117329#issuecomment-1951981106)

Cc `@nikic`
2024-05-22 13:04:14 +00:00
bors
6715446db6 Auto merge of #125358 - matthiaskrgr:rollup-mx841tg, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #124570 (Miscellaneous cleanups)
 - #124772 (Refactor documentation for Apple targets)
 - #125011 (Add opt-for-size core lib feature flag)
 - #125218 (Migrate `run-make/no-intermediate-extras` to new `rmake.rs`)
 - #125225 (Use functions from `crt_externs.h` on iOS/tvOS/watchOS/visionOS)
 - #125266 (compiler: add simd_ctpop intrinsic)
 - #125348 (Small fixes to `std::path::absolute` docs)

Failed merges:

 - #125296 (Fix `unexpected_cfgs` lint on std)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-21 12:50:09 +00:00
Matthias Krüger
fd975f75fa
Rollup merge of #125266 - workingjubilee:stream-plastic-love, r=RalfJung,nikic
compiler: add simd_ctpop intrinsic

Fairly straightforward addition.

cc `@rust-lang/opsem` new (extremely boring) intrinsic
2024-05-21 12:47:06 +02:00
Michael Goulet
917bb8396c Fix miri too 2024-05-20 19:21:38 -04:00
Jubilee Young
1185a6486c miri: support simd_ctpop 2024-05-19 18:48:06 -07:00
Matthias Krüger
7a45322300
Rollup merge of #125286 - RalfJung:miri-sync, r=RalfJung
Miri subtree update

r? `@ghost`
2024-05-19 22:50:56 +02:00
bors
85ed056888 Auto merge of #3319 - bjorn3:some_more_shims, r=RalfJung
Directly implement native exception raise methods in miri

This implements the `_Unwind_RaiseException` function used on pretty much every unix system for starting unwinding. This allows removing the miri special case from libpanic_unwind for unix.

Windows still needs `miri_start_unwind` as SEH unwinding isn't supported by miri. Unlike DWARF unwinding, SEH preserves all stack frames until right after the do_catch function has executed. Because of this panic_unwind stack allocates the exception object. Miri can't currently model unwinding without destroying stack frames and as such will report a use-after-free of the exception object.
2024-05-19 17:35:20 +00:00
Ralf Jung
5e41ff516f various small nits
- share implementation with miri_starting_unwind
- make test use a custom unwinding class
- extend comments
- use NeedsUnwind more consistently
2024-05-19 19:31:52 +02:00
bjorn3
42cb1ffa36 Directly implement native exception raise methods in miri
Windows still needs the old custom ABI as SEH unwinding isn't supported
by miri. Unlike DWARF unwinding it preserves all stack frames until
right after the do_catch function has executed. Because of this
panic_unwind stack allocates the exception object. Miri can't currently
model unwinding without destroying stack frames and as such will report
a use-after-free of the exception object.
2024-05-19 19:06:31 +02:00
Ralf Jung
9cba160d52 use a little arg-parsing helper for miri-script 2024-05-19 18:57:22 +02:00
Ralf Jung
b8a7c73792 test wasm32-wasip2 instead of the deprecated wasm32-wasi target 2024-05-19 16:48:48 +02:00
Ralf Jung
2b9c1caa18 properly print error in 'cargo miri setup --print-sysroot' 2024-05-19 14:01:52 +02:00
bors
0e41a801f3 Auto merge of #3616 - RalfJung:android, r=RalfJung
make basic things work on Android

Fixes https://github.com/rust-lang/miri/issues/3608
2024-05-19 10:14:36 +00:00
bors
3726afad7e Auto merge of #3585 - devnexen:aligned_alloc, r=RalfJung
support aligned_alloc for unixes.

Fixes https://github.com/rust-lang/miri/issues/3577
2024-05-19 09:50:25 +00:00
Ralf Jung
844de64396 make basic things work on Android 2024-05-19 11:50:12 +02:00
Ralf Jung
430298c3ad a bit of refactoring and tweak the aligned-allocation tests 2024-05-19 11:48:51 +02:00
Ralf Jung
1ba83f2dc1 Preparing for merge from rustc 2024-05-19 10:35:38 +02:00
blyxyas
c5c820e7fb Fix typos (taking into account review comments) 2024-05-18 18:12:18 +02:00
David Carlier
5ea21ca486
support aligned_alloc for unixes support. 2024-05-18 12:45:34 +01:00
marc0246
318a0fe586
Ignore the Helix configuration directory 2024-05-17 22:58:25 +02:00
bors
5b2fdb6d40 Auto merge of #3603 - Luv-Ray:issue-3572, r=RalfJung
Give `FileDescription::{read, write}` access to the `MiriInterpCx `

fixes #3572
2024-05-17 16:36:33 +00:00
bors
fffc8e9b43 Auto merge of #3526 - Strophox:miri-memory, r=RalfJung
Adjust Allocation Bytes used by Miri to custom MiriAllocBytes

Previously, the `MiriMachine` used `type Bytes = Box<[u8]>` for its allocations.
This PR swaps this out for a custom `MiriAllocBytes` type implemented in `alloc_bytes.rs`.
This is in anticipation of an extension to Miri's FFI, which will require its allocations to take care of alignment (the methods in `impl AllocBytes for Box<[u8]>` ignore this `_align: Align` argument).

Needs https://github.com/rust-lang/rust/pull/124492
2024-05-17 06:19:50 +00:00
Strophox
983fb093ff start implementing MiriAllocBytes
attempt changing Bytes in MiriMachine to MiriAllocBytes

rename miri_alloc_bytes to alloc_bytes

generalize impl VisitProvenance for Allocation for any Bytes: AllocBytes

mend MiriAllocBytes -> Self::Bytes

fix Invariant documentation and bugs (drop), impl Clone

Update MiriAllocBytes description

Co-authored-by: Ralf Jung <post@ralfj.de>

Rephrase MiriAllocBytes ptr invariant

Co-authored-by: Ralf Jung <post@ralfj.de>

Update MiriAllocBytes ptr documentation

Co-authored-by: Ralf Jung <post@ralfj.de>

fix safety comment in MiriAllocBytes::clone

fix safety comment in MiriAllocBytes::from_bytes

try implementing clone without unsafe

remove derive(PartialEq,Eq,Hash), fix fmt

move ptr.is_null() check inside only necessary branch

use std::ptr::without_provenance_mut, requiring feature(strict_provenance)

align.bytes_usize() instead of align.bytes().try_into().unwrap()

Update src/provenance_gc.rs

Co-authored-by: Ralf Jung <post@ralfj.de>

fix clippy error on deref
2024-05-16 16:04:20 +02:00
Ralf Jung
6d314f3b11 alloc now works on wasi (and some formatting) 2024-05-16 11:25:44 +02:00
Ralf Jung
b1b278b17b Preparing for merge from rustc 2024-05-16 10:40:05 +02:00
Luv-Ray
99c6b2e604 Give FileDescription::{read, write} access to the InterpCx 2024-05-13 16:17:56 +08:00
bors
d0b2c6611b Auto merge of #3604 - RalfJung:intrinsics, r=RalfJung
intrinsics: just panic when they get used incorrectly

This is already what we do most of the time, so do it consistently.
2024-05-13 06:24:47 +00:00
Ralf Jung
c6a0e2ca4c intrinsics: just panic when they get used incorrectly 2024-05-13 08:21:05 +02:00
Ralf Jung
5c33a5690d offset, offset_from: allow zero-byte offset on arbitrary pointers 2024-05-13 07:59:16 +02:00
bors
d4937cb229 Auto merge of #3575 - devnexen:illumos_part3, r=RalfJung
Illumos part3

Fixes https://github.com/rust-lang/miri/issues/3567
2024-05-12 20:33:36 +00:00
David Carlier
10acfd9f77 further illumos/solaris support.
fixing part of `miri test alloc/hashmap`.
2024-05-12 19:59:09 +00:00
bors
e4f81d1bb2 Auto merge of #3599 - saethlin:quiet-when-no-change, r=RalfJung
Don't print unnecessary sysroot messages

Currently, when running `cargo miri setup`, we always print that a sysroot is being prepared, even if we just bail out of building after checking the hash. So that message is wrong; we didn't actually prepare a sysroot.

We also always print the preparing message for `cargo miri run`, even if no sysroot is prepared.

With this PR, `cargo miri run` prints no sysroot messages when an existing one is reused, and when a redundant `cargo miri setup` is requested, we print:
```
A sysroot for Miri is already available in `/home/ben/.cache/miri`.
```
2024-05-12 18:35:24 +00:00
Ben Kimock
cd7527aa35 Don't print unnecessary sysroot messages 2024-05-12 14:31:22 -04:00
Ralf Jung
7d565dfa0f Preparing for merge from rustc 2024-05-12 15:44:17 +02:00
Ralf Jung
01b5430b28 merge two integer tests 2024-05-12 10:25:51 +02:00
Ralf Jung
5d76ec9cdd merge float tests into one 2024-05-12 10:21:00 +02:00
Ralf Jung
9fc569d67f organize float intrinsic implementations a bit 2024-05-12 10:12:33 +02:00
tiif
bf5906fbb4 Add non-null pointer for posix_memalign 2024-05-12 15:01:18 +08:00
bors
32b2238174 Auto merge of #3596 - bend-n:support_fstar_algebraic, r=RalfJung
support `f*_algebraic`

supports the [`f*_algebraic`](https://doc.rust-lang.org/std/intrinsics/fn.fadd_algebraic.html) intrinsics.
2024-05-11 10:32:28 +00:00
bendn
e928185f6e
support f*_algebraic 2024-05-11 17:13:20 +07:00
bors
79a85d4e99 Auto merge of #3598 - RalfJung:heap, r=RalfJung
alloc: update comments around malloc() alignment

Also separate the C heap shims form the Windows heap shims; their guarantees aren't quite the same.
2024-05-11 08:53:42 +00:00
Ralf Jung
01b151ebd4 separate windows heap functions from C heap shims 2024-05-11 10:52:08 +02:00
Ralf Jung
7a0ee91ba5 alloc: update comments around malloc() alignment 2024-05-11 10:52:02 +02:00
The Miri Cronjob Bot
ce3daac283 Merge from rustc 2024-05-11 05:03:34 +00:00
The Miri Cronjob Bot
4d63d0af4d Preparing for merge from rustc 2024-05-11 04:56:14 +00:00
Ralf Jung
25a3b6687e rename 'extern-so' to 'native-lib' 2024-05-10 18:30:48 +02:00
Matthias Krüger
9a9ec90567
Rollup merge of #124957 - compiler-errors:builtin-deref, r=michaelwoerister
Make `Ty::builtin_deref` just return a `Ty`

Nowhere in the compiler are we using the mutability part of the `TyAndMut` that we used to return.
2024-05-10 16:10:47 +02:00
Michael Goulet
d50c2b0a52 Make builtin_deref just return a Ty 2024-05-09 22:55:00 -04:00
Ralf Jung
41d36a0951 interpret/miri: better errors on failing offset_from 2024-05-09 13:09:47 +02:00