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

validate basic sanity for TerminatorKind #72810

Merged
merged 4 commits into from
Jun 7, 2020

Conversation

RalfJung
Copy link
Member

r? @jonas-schievink

This mainly checks that all BasicBlock actually exist. On top of that, it checks that Call actually calls something of FnPtr/FnDef type, and Assert has to work on a bool. Also SwitchInt cannot have an empty target list.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 31, 2020
@RalfJung RalfJung force-pushed the mir-terminate-sanity branch from 37676c2 to 5707838 Compare May 31, 2020 08:50
self.check_bb(terminator.source_info.span, *drop);
}
}
TerminatorKind::FalseEdges { real_target, imaginary_target } => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, does anyone know why this is named in plural? Shouldn't it be FalseEdge instead?
Cc @matthewjasper

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it may have been accurate in the past. Feel free to change it.

@RalfJung RalfJung force-pushed the mir-terminate-sanity branch from 24578ea to e07e424 Compare May 31, 2020 12:49
@RalfJung RalfJung force-pushed the mir-terminate-sanity branch from 9a78edd to f793c0b Compare May 31, 2020 13:23
@jonas-schievink
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 31, 2020

📌 Commit f793c0b has been approved by jonas-schievink

@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 May 31, 2020
RalfJung added a commit to RalfJung/rust that referenced this pull request Jun 1, 2020
…nas-schievink

validate basic sanity for TerminatorKind

r? @jonas-schievink

This mainly checks that all `BasicBlock` actually exist. On top of that, it checks that `Call` actually calls something of `FnPtr`/`FnDef` type, and `Assert` has to work on a `bool`. Also `SwitchInt` cannot have an empty target list.
self.check_bb(location, *unwind);
}
}
TerminatorKind::Call { func, destination, cleanup, .. } => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call (and perhaps others?) could also validate that the destination doesn't overlap with any of the arguments. This would have caught a miscompilation in #72632.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DropAndReplace (and Yield?) can do the same check. Not sure about inline assembly, but it seems like that's a candidate for such a check as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, now I wonder if Miri would have caught that (for Call). Unfortunately we can't test Miri on MIR that rustc does not generate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably would have, but I haven't yet figured out how to use a locally built miri with external code (like with cargo-miri).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably would have, but I haven't yet figured out how to use a locally built miri with external code (like with cargo-miri).

I usually do ./miri install and then use cargo miri.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./src/tools/miri/miri install fails with "can't find crate for rustc_apfloat" for me, and running the miri tests ICEs the compiler

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I've only ever used the script in a standalone clone... yeah it probably doesn't work in the rustc folder layout.

running the miri tests ICEs the compiler

How do you run them? ./x.py test --stage 0 src/tools/miri should work -- except when the Miri toolstate is broken for the commit you're basing your work on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what I tried to run, but it enters unreachable code while decoding or encoding something. Not really sure what's happening, but I'll do more digging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like an incremental problem or --keep-stage gone wrong... strange.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Jun 4, 2020
…nas-schievink

validate basic sanity for TerminatorKind

r? @jonas-schievink

This mainly checks that all `BasicBlock` actually exist. On top of that, it checks that `Call` actually calls something of `FnPtr`/`FnDef` type, and `Assert` has to work on a `bool`. Also `SwitchInt` cannot have an empty target list.
@oli-obk oli-obk added the A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html label Jun 6, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 7, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#72810 (validate basic sanity for TerminatorKind)
 - rust-lang#72989 (Revert pr 71840)
 - rust-lang#72993 (Count the beta prerelease number just from master)
 - rust-lang#73057 (Clean up E0644 explanation)
 - rust-lang#73059 (remove outdated comment)

Failed merges:

r? @ghost
@bors bors merged commit 63b314c into rust-lang:master Jun 7, 2020
@RalfJung RalfJung deleted the mir-terminate-sanity branch June 7, 2020 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html 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