Skip to content

miri: better ptr-out-of-bounds errors #87224

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

Merged
merged 1 commit into from
Jul 20, 2021
Merged

Conversation

RalfJung
Copy link
Member

For offsets larger than isize::MAX, display them as negative offsets.

r? @oli-obk

@rust-highfive
Copy link
Contributor

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 17, 2021
@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

I don't think it is possible to trigger the negative case in CTFE, but it is possible in Miri: rust-lang/miri#1853.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 18, 2021

well... we can run the same code in CTFE: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=6670eb77e14af454abf6f33d1523f4b2

... but the error message is absolutely useless:

warning: unused variable: `x`
 --> src/lib.rs:5:9
  |
5 |     let x = unsafe { x.offset(-1) };
  |         ^ help: if this is intentional, prefix it with an underscore: `_x`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: constant is never used: `FOO`
 --> src/lib.rs:2:1
  |
2 | / const FOO: () = {
3 | |     let v = [0i8; 4];
4 | |     let x = &v as *const i8;
5 | |     let x = unsafe { x.offset(-1) };
6 | | };
  | |__^
  |
  = note: `#[warn(dead_code)]` on by default

error[E0080]: evaluation of constant value failed
    | 
   ::: src/lib.rs:5:22
    |
5   |     let x = unsafe { x.offset(-1) };
    |                      ------------ inside `FOO` at src/lib.rs:5:22

For more information about this error, try `rustc --explain E0080`.
error: could not compile `playground` due to previous error; 2 warnings emitted

I don't know how this happened, it sounds to me like the intrinsic call is treated as a separate const evaluation?

@RalfJung
Copy link
Member Author

The same test as CTFE doesn't work since offset(-1) will overflow (which is a different error message than going out-of-bounds).

But I found a test that works. :)

I don't know how this happened, it sounds to me like the intrinsic call is treated as a separate const evaluation?

The actual error span is inside the offset implementation. So the inside `FOO` at src/lib.rs:5:22 is just part of the backtrace. But I am not sure why the other span is not shown...

@oli-obk
Copy link
Contributor

oli-obk commented Jul 18, 2021

But I am not sure why the other span is not shown...

because we don't have the libcore source available. we should still print messages, even if the source of a span is missing. probably will get solved when we put the error message as the main message, instead of a label

@oli-obk
Copy link
Contributor

oli-obk commented Jul 18, 2021

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 18, 2021

📌 Commit bed3b96 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 Jul 18, 2021
@bors
Copy link
Collaborator

bors commented Jul 20, 2021

⌛ Testing commit bed3b96 with merge 718d53b...

@bors
Copy link
Collaborator

bors commented Jul 20, 2021

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 718d53b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 20, 2021
@bors bors merged commit 718d53b into rust-lang:master Jul 20, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 20, 2021
@rust-highfive
Copy link
Contributor

📣 Toolstate changed by #87224!

Tested on commit 718d53b.
Direct link to PR: #87224

💔 miri on windows: test-fail → build-fail (cc @oli-obk @RalfJung @eddyb).
💔 miri on linux: test-fail → build-fail (cc @oli-obk @RalfJung @eddyb).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Jul 20, 2021
Tested on commit rust-lang/rust@718d53b.
Direct link to PR: <rust-lang/rust#87224>

💔 miri on windows: test-fail → build-fail (cc @oli-obk @RalfJung @eddyb).
💔 miri on linux: test-fail → build-fail (cc @oli-obk @RalfJung @eddyb).
bors added a commit to rust-lang/miri that referenced this pull request Jul 20, 2021
better errors for negative out-of-bounds offsets

This is the Miri side of rust-lang/rust#87224
@RalfJung RalfJung deleted the miri-ptr-oob branch July 24, 2021 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants