-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly determine which terminators can have side effects
The previous code ignored that `Drop` terminators could execute custom `Drop` implementations which might mutate the environment. Now we correctly implement `has_side_effects` and tests that custom `Drop` impls are recorded as an indirect definition.
- Loading branch information
1 parent
cfd9320
commit 047e7ca
Showing
4 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![feature(core_intrinsics, rustc_attrs)] | ||
use std::intrinsics::rustc_peek; | ||
|
||
struct NoSideEffectsInDrop<'a>(&'a mut u32); | ||
struct SideEffectsInDrop<'a>(&'a mut u32); | ||
|
||
impl Drop for SideEffectsInDrop<'_> { | ||
fn drop(&mut self) { | ||
*self.0 = 42 | ||
} | ||
} | ||
|
||
#[rustc_mir(rustc_peek_use_def_chain, stop_after_dataflow, borrowck_graphviz_postflow="flow.dot")] | ||
fn main() { | ||
let mut x; | ||
x=0; | ||
|
||
NoSideEffectsInDrop(&mut x); | ||
SideEffectsInDrop(&mut x); | ||
|
||
// The ";" on line 19 is the point at which `SideEffectsInDrop` is dropped. | ||
unsafe { rustc_peek(x); } | ||
//~^ ERROR rustc_peek: [16: "x=0", 19: ";"] | ||
|
||
assert_eq!(x, 42); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: rustc_peek: [16: "x=0", 19: ";"] | ||
--> $DIR/reaching-defs-drop.rs:22:14 | ||
| | ||
LL | unsafe { rustc_peek(x); } | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: stop_after_dataflow ended compilation | ||
|
||
error: aborting due to 2 previous errors | ||
|