Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpret: make isize::MAX the limit for dynamic value sizes #95388

Merged
merged 4 commits into from
Apr 1, 2022

Conversation

RalfJung
Copy link
Member

We are currently enforcing data_layout.obj_size_bound() as the maximal dynamic size of a Rust value (including for size_of_val_raw), but that does not match the docs.

In particular, Miri currently falsely says that this code has UB:

#![feature(layout_for_ptr)]
fn main() {
    let size = isize::MAX as usize;
    // Creating a raw slice of size isize::MAX and asking for its size is okay.
    let s = std::ptr::slice_from_raw_parts(1usize as *const u8, size);
    assert_eq!(size, unsafe { std::mem::size_of_val_raw(s) });
}

@rust-highfive
Copy link
Collaborator

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 27, 2022
@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 27, 2022
@RalfJung
Copy link
Member Author

r? @oli-obk

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 30, 2022
allow large Size again

This basically reverts most of rust-lang#80042, and instead does the panic in `bits()` with a `#[cold]` function to make sure it does not get inlined.

rust-lang#80042 added a comment about an invariant ("The top 3 bits are ALWAYS zero") that is not actually enforced, and if it were enforced that would be a problem for rust-lang#95388. So I think we should not have that invariant, and I adjusted the code accordingly.

r? `@oli-obk` Cc `@sivadeilra`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 31, 2022
allow large Size again

This basically reverts most of rust-lang#80042, and instead does the panic in `bits()` with a `#[cold]` function to make sure it does not get inlined.

rust-lang#80042 added a comment about an invariant ("The top 3 bits are ALWAYS zero") that is not actually enforced, and if it were enforced that would be a problem for rust-lang#95388. So I think we should not have that invariant, and I adjusted the code accordingly.

r? `@oli-obk` Cc `@sivadeilra`
@oli-obk
Copy link
Contributor

oli-obk commented Mar 31, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Mar 31, 2022

📌 Commit cb0d15b has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 31, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 1, 2022
…askrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#95032 (Clean up, categorize and sort unstable features in std.)
 - rust-lang#95260 (Better suggestions for `Fn`-family trait selection errors)
 - rust-lang#95293 (suggest wrapping single-expr blocks in square brackets)
 - rust-lang#95344 (Make `impl Debug for rustdoc::clean::Item` easier to read)
 - rust-lang#95388 (interpret: make isize::MAX the limit for dynamic value sizes)
 - rust-lang#95530 (rustdoc: do not show primitives and keywords as private)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit cdf178f into rust-lang:master Apr 1, 2022
@rustbot rustbot added this to the 1.61.0 milestone Apr 1, 2022
bors added a commit to rust-lang/miri that referenced this pull request Apr 1, 2022
Rust values can be up to isize::MAX in size

Needs rust-lang/rust#95388
@RalfJung RalfJung deleted the rust-val-limit branch April 1, 2022 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants