summary refs log tree commit diff
path: root/compiler/rustc_mir/src/interpret
AgeCommit message (Collapse)AuthorLines
2021-07-22rename assert_matches moduleJane Lusby-1/+1
2021-07-22Move [debug_]assert_matches to mod {core, std}::assert.Mara Bos-0/+1
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
2021-05-25`can_unwind` -> `caller_can_unwind`hyd-dev-2/+2
2021-05-25Check whether unwinding is allowed before popping the stack framehyd-dev-16/+15
2021-05-23:facepalm:hyd-dev-1/+1
2021-05-23Pass `StackPopUnwind` to `eval_fn_call()` and some other functions that are ↵hyd-dev-21/+25
called by `eval_fn_call()`
2021-05-23"unwind" -> "unwinding"hyd-dev-1/+1
2021-05-23`Cleanup(Option<_>)` -> `Cleanup(BasicBlock), Skip`hyd-dev-6/+9
2021-05-23support creating mutable allocations from byte slicesRalf Jung-6/+16
2021-05-23avoid redundant immutability checkRalf Jung-3/+0
2021-05-23reject deallocation of read-only allocationsRalf Jung-0/+3
2021-05-23Don't evaluate `self.fn_can_unwind(...)` if `can_unwind` is already truehyd-dev-3/+4
2021-05-23Refactor `match` + `if`hyd-dev-12/+9
2021-05-23Move the callee "can unwind" check to the right placehyd-dev-38/+37
2021-05-23const-eval: disallow unwinding across functions that `!fn_can_unwind()`hyd-dev-11/+67
2021-05-22Auto merge of #85578 - RalfJung:alloc-mem-extra, r=oli-obkbors-2/+3
CTFE get_alloc_extra_mut: also provide ref to MemoryExtra This would let me use mutable references in more places in Stacked Borrows, avoiding some `RefCell` overhead. :) r? `@oli-obk`
2021-05-22CTFE get_alloc_extra_mut: also provide ref to MemoryExtraRalf Jung-2/+3
2021-05-22Add default implementation for `enforce_abi()`hyd-dev-6/+3
2021-05-21Add `rustc_mir::interpret::Machine::enforce_abi()`hyd-dev-19/+29
2021-05-19CTFE Machine: do not expose AllocationRalf Jung-9/+11
2021-05-18fix mplace_access_checked with forced alignmentRalf Jung-2/+3
2021-05-18add Align::ONE; add methods to access alloc.extraRalf Jung-17/+26
2021-05-18reduce number of allocation lookups during copyRalf Jung-6/+6
2021-05-18CTFE core engine allocation & memory API improvemenetsRalf Jung-259/+410
- make Allocation API offset-based (no more Pointer) - make Memory API higher-level (combine checking for access and getting access into one operation)
2021-05-17Rollup merge of #85412 - RalfJung:c_str, r=oli-obkRalf Jung-75/+0
remove some functions that were only used by Miri and Miri does not need them any more with https://github.com/rust-lang/miri/pull/1805. r? ``@oli-obk``
2021-05-17Rollup merge of #85408 - RalfJung:alloc-size, r=oli-obkRalf Jung-7/+7
remove size field from Allocation This is a part of https://github.com/rust-lang/rust/pull/85376 that can be easily split out. r? ``@oli-obk``
2021-05-17Rollup merge of #85087 - hyd-dev:lots-of-abis, r=RalfJungRalf Jung-11/+18
`eval_fn_call`: check the ABI of `body.source` And stop checking `instance_ty.fn_sig(*self.tcx).abi()`, if the function is not an intrinsic. Addresses https://github.com/rust-lang/miri/pull/1776#discussion_r615381169. No idea how to test this without Miri...
2021-05-17Add a comment for `check_abi()`hyd-dev-0/+3
2021-05-17remove some functions that were only used by MiriRalf Jung-75/+0
2021-05-17remove size field from AllocationRalf Jung-7/+7
2021-05-15handle pointers in strRalf Jung-0/+1
2021-05-12entirely remove rustc_args_required_const attributeRalf Jung-9/+0
2021-05-12Auto merge of #83813 - cbeuw:remap-std, r=michaelwoeristerbors-2/+8
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
2021-05-09Check the ABI of `body.source`hyd-dev-11/+15