summary refs log tree commit diff
path: root/compiler/rustc_mir/src/interpret
AgeCommit message (Collapse)AuthorLines
2021-07-18miri: better ptr-out-of-bounds errorsRalf Jung-4/+10
2021-07-17Auto merge of #87123 - RalfJung:miri-provenance-overhaul, r=oli-obkbors-629/+581
CTFE/Miri engine Pointer type overhaul This fixes the long-standing problem that we are using `Scalar` as a type to represent pointers that might be integer values (since they point to a ZST). The main problem is that with int-to-ptr casts, there are multiple ways to represent the same pointer as a `Scalar` and it is unclear if "normalization" (i.e., the cast) already happened or not. This leads to ugly methods like `force_mplace_ptr` and `force_op_ptr`. Another problem this solves is that in Miri, it would make a lot more sense to have the `Pointer::offset` field represent the full absolute address (instead of being relative to the `AllocId`). This means we can do ptr-to-int casts without access to any machine state, and it means that the overflow checks on pointer arithmetic are (finally!) accurate. To solve this, the `Pointer` type is made entirely parametric over the provenance, so that we can use `Pointer<AllocId>` inside `Scalar` but use `Pointer<Option<AllocId>>` when accessing memory (where `None` represents the case that we could not figure out an `AllocId`; in that case the `offset` is an absolute address). Moreover, the `Provenance` trait determines if a pointer with a given provenance can be cast to an integer by simply dropping the provenance. I hope this can be read commit-by-commit, but the first commit does the bulk of the work. It introduces some FIXMEs that are resolved later. Fixes https://github.com/rust-lang/miri/issues/841 Miri PR: https://github.com/rust-lang/miri/pull/1851 r? `@oli-obk`
2021-07-16avoid manual Debug impls by adding extra Provenance bounds to typesRalf Jung-149/+46
I wish the derive macro would support adding extra where clauses...
2021-07-16rename assert_matches moduleJane Lusby-1/+1
2021-07-16get rid of incorrect erase_for_fmtRalf Jung-54/+48
2021-07-15make check_ptr_access_align work on function pointer allocationsRalf Jung-6/+12
2021-07-15enable Miri to fix the bytes in an allocation (since ptr offsets have ↵Ralf Jung-53/+41
different meanings there)
2021-07-15adjustions and cleanup to make Miri build againRalf Jung-135/+115
2021-07-15Rollup merge of #86947 - m-ou-se:assert-matches-to-submodule, r=yaahcYuki Okushi-0/+1
Move assert_matches to an inner module Fixes #82913
2021-07-14remove unused error variantRalf Jung-8/+3
2021-07-14more precise message for the ptr access check on derefRalf Jung-8/+7
2021-07-14use NonZeroU64 for AllocId to restore old type sizesRalf Jung-7/+7
2021-07-14consistently treat None-tagged pointers as ints; get rid of some deprecated ↵Ralf Jung-27/+35
Scalar methods
2021-07-14CTFE/Miri engine Pointer type overhaul: make Scalar-to-Pointer conversion ↵Ralf Jung-459/+544
infallible This resolves all the problems we had around "normalizing" the representation of a Scalar in case it carries a Pointer value: we can just use Pointer if we want to have a value taht we are sure is already normalized.
2021-07-12remove unnecessary deallocate_local hackRalf Jung-15/+8
2021-07-12remove remaining use of Pointer in Allocation APIRalf Jung-2/+2
2021-07-09Rollup merge of #87000 - m-ou-se:const-panic-track-caller, r=oli-obkMara Bos-2/+11
Use #[track_caller] in const panic diagnostics. This change stops const panic diagnostics from reporting inside #[track_caller] functions by skipping over them.
2021-07-09Use #[track_caller] in const panic diagnostics.Mara Bos-2/+11
It was already used for the message. This also uses it for the spans used for the error and backtrace.
2021-07-08PR feedbackScott McMurray-1/+2
- Add `:Sized` assertion in interpreter impl - Use `Scalar::from_bool` instead of `ScalarInt: From<bool>` - Remove unneeded comparison in intrinsic typeck - Make this UB to call with undef, not just return undef in that case
2021-07-08Stop generating `alloca`s+`memcmp` for simple array equalityScott McMurray-0/+18
2021-07-08Move [debug_]assert_matches to mod {core, std}::assert.Mara Bos-0/+1
2021-07-04Combine individual limit queries into single `limits` queryAaron Hill-1/+1
2021-07-04Query-ify global limit attribute handlingAaron Hill-0/+5
2021-07-03Make vtable_allocation always succeedSmitty-1/+1
2021-07-02Allocation failure in constprop panics right awaySmitty-1/+4
2021-06-29Unwrap allocated Location at creationSmitty-9/+8
2021-06-29Support allocation failures when interperting MIRSmitty-16/+19
Note that this breaks Miri. Closes #79601
2021-06-28Update other codegens to use tcx managed vtable allocations.Charles Lew-91/+6
2021-06-27Change miri to use tcx allocated allocations.Charles Lew-29/+36
2021-06-16Auto merge of #86291 - crlf0710:trait_vtbl_refactor, r=bjorn3bors-35/+57
Refactor vtable codegen This refactor the codegen of vtables of miri interpreter, llvm, cranelift codegen backends. This is preparation for the implementation of trait upcasting feature. cc #65991 Note that aside from code reorganization, there's an internal behavior change here that now InstanceDef::Virtual's index now include the three metadata slots, and now the first method is with index 3. cc `@RalfJung` `@bjorn3`
2021-06-15Refactor to make interpreter and codegen backend neutral to vtable internal ↵Charles Lew-35/+57
representation.
2021-06-14Adjust `throw_validation_failure` macro to shorten the use of ↵Rémy Rakic-13/+10
`with_no_trimmed_paths`
2021-06-13Improve CTFE validation error messageRémy Rakic-8/+12
2021-06-13Turn incorrect vtable size/alignment errors into hard const-UB errorsRémy Rakic-9/+10
They were "freeform const UB" error message, but could reach validation and trigger ICEs there. We now catch them during validation to avoid that.
2021-06-12Rollup merge of #86174 - lqd:const-ub-align, r=RalfJungYuki Okushi-1/+3
Detect incorrect vtable alignment during const eval This PR fixes #86132 by detecting invalid alignment values for trait objects in the interpreter, and emitting an error about this conversion failure, to avoid the ICE. I've noticed that the error emitted at https://github.com/rust-lang/rust/blob/a50d72158e08e02cfc051b863017bdbd2c45b637/compiler/rustc_mir/src/interpret/traits.rs#L163-L166 doesn't seem to be present in the const-ub tests, so I've tried adding a test that triggers both of these cases: one for the invalid size, and another for the invalid alignment that #86132 tracks (I have found different magic values triggering different `Align::from_bytes` errors than the "power of 2" one, if need be). However, when doing that, I *cannot* for the life of me figure out the correct incantation to make these 2 errors trigger with the "it is undefined behavior to use this value" message rather than the "any use of this value will cause an error" lint. I've tried Oli's suggestions of different values, tuples and arrays, using the transparent wrapper trick from the other tests and I was only able to trigger the regular const-ub errors about the size of the vtable, or that the drop pointer was invalid. Maybe these "type validation failed" errors happen before this part of the interpreter is reached and there just needs some magic incorrect values to bypass them, I don't know. Since this fixes an ICE, and if the constants are indeed used, these 2 tests will turn into a hard error, I thought I'd open the PR anyways. And if ```@RalfJung``` you know of a way I could manage that (if you think that these tests are worth checking that the `throw_ub_format!` does indeed create const-ub errors as we expect) I'd be grateful. For that reason, r? ```@RalfJung``` and cc ```@oli-obk.```
2021-06-09detect incorrect vtable alignment during const eval instead of ICE-ingRémy Rakic-1/+3
also add tests for these 2 kinds of errors for size and alignment, as the existing size check wasn't apparently tested
2021-06-05Explain that `ensure_monomorphic_enough` omission is intentionalTomasz Miąsko-0/+2
2021-06-05Disallow non-monomorphic calls to `needs_drop` in interpreterTomasz Miąsko-1/+4
otherwise evaluation could change after further substitutions.
2021-06-04Rollup merge of #85963 - m-ou-se:constructor-type-name, r=yaahcYuki Okushi-6/+1
Show `::{{constructor}}` in std::any::type_name(). Fix #84666 Before: ``` [src/main.rs:6] type_name::<T>() = "playground::Velocity" [src/main.rs:6] type_name::<T>() = "playground::Velocity" ``` After: ``` [src/main.rs:6] type_name::<T>() = "scratchpad::Velocity::{{constructor}}" [src/main.rs:6] type_name::<T>() = "scratchpad::Velocity" ``` cc ``@scottmcm``
2021-06-03Show `::{{constructor}}` in std::any::type_name().Mara Bos-6/+1
2021-06-02Restrict access to crate_name.Camille GILLOT-1/+1
Also remove original_crate_name, which had the exact same implementation
2021-06-01Revert "Reduce the amount of untracked state in TyCtxt"Camille Gillot-1/+1
2021-05-30Restrict access to crate_name.Camille GILLOT-1/+1
Also remove original_crate_name, which had the exact same implementation
2021-05-28Auto merge of #85546 - hyd-dev:unwind, r=RalfJungbors-55/+121
const-eval: disallow unwinding across functions that `!fn_can_unwind()` Following https://github.com/rust-lang/miri/pull/1776#discussion_r633074343, so r? `@RalfJung` This PR turns `unwind` in `StackPopCleanup::Goto` into a new enum `StackPopUnwind`, with a `NotAllowed` variant to indicate that unwinding is not allowed. This variant is chosen based on `rustc_middle::ty::layout::fn_can_unwind()` in `eval_fn_call()` when pushing the frame. A check is added in `unwind_to_block()` to report UB if unwinding happens across a `StackPopUnwind::NotAllowed` frame. Tested with Miri `HEAD` with [minor changes](https://github.com/rust-lang/miri/compare/HEAD..9cf3c7f0d86325a586fbcbf2acdc9232b861f1d8) and the rust-lang/miri#1776 branch with [these changes](https://github.com/rust-lang/miri/compare/d866c1c52f48bf562720383455b75c257bb1ad92..626638fbfe2fff34648dda29a34d59db498a6e52).
2021-05-28Rewrite to a `match`hyd-dev-5/+4
2021-05-28"a frame" -> "a stack frame"hyd-dev-1/+1
2021-05-26Remove unneeded workaroundSmitty-5/+3
This removes a workaround for #24159, which has been fixed.
2021-05-26Use `match` instead of `.map_or(StackPopUnwind::Skip, StackPopUnwind::Cleanup)`hyd-dev-5/+8
2021-05-25Move the check to `unwind_to_block`hyd-dev-30/+34
2021-05-25Add a commenthyd-dev-0/+1