Skip to content

Commit 968911d

Browse files
authored
Rollup merge of #111432 - cjgillot:issue-111426, r=oli-obk
Use visit_assign to detect SSA locals. I screwed up the logic in 3c43b61. Fixes #111426
2 parents 3b7c02b + 6ad0497 commit 968911d

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

compiler/rustc_mir_transform/src/ssa.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,6 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor {
209209
match ctxt {
210210
PlaceContext::MutatingUse(MutatingUseContext::Projection)
211211
| PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) => bug!(),
212-
PlaceContext::MutatingUse(MutatingUseContext::Store) => {
213-
self.assignments[local].insert(LocationExtended::Plain(loc));
214-
if let Set1::One(_) = self.assignments[local] {
215-
// Only record if SSA-like, to avoid growing the vector needlessly.
216-
self.assignment_order.push(local);
217-
}
218-
}
219212
// Anything can happen with raw pointers, so remove them.
220213
// We do not verify that all uses of the borrow dominate the assignment to `local`,
221214
// so we have to remove them too.
@@ -252,6 +245,19 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor {
252245
self.visit_local(place.local, ctxt, loc);
253246
}
254247
}
248+
249+
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, loc: Location) {
250+
if let Some(local) = place.as_local() {
251+
self.assignments[local].insert(LocationExtended::Plain(loc));
252+
if let Set1::One(_) = self.assignments[local] {
253+
// Only record if SSA-like, to avoid growing the vector needlessly.
254+
self.assignment_order.push(local);
255+
}
256+
} else {
257+
self.visit_place(place, PlaceContext::MutatingUse(MutatingUseContext::Store), loc);
258+
}
259+
self.visit_rvalue(rvalue, loc);
260+
}
255261
}
256262

257263
#[instrument(level = "trace", skip(ssa, body))]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- // MIR for `main` before CopyProp
2+
+ // MIR for `main` after CopyProp
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/partial_init.rs:+0:15: +0:15
6+
let mut _1: (isize,); // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
7+
8+
bb0: {
9+
(_1.0: isize) = const 1_isize; // scope 0 at $DIR/partial_init.rs:+4:13: +4:20
10+
return; // scope 0 at $DIR/partial_init.rs:+5:13: +5:21
11+
}
12+
}
13+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// unit-test: CopyProp
2+
// Verify that we do not ICE on partial initializations.
3+
4+
#![feature(custom_mir, core_intrinsics)]
5+
extern crate core;
6+
use core::intrinsics::mir::*;
7+
8+
// EMIT_MIR partial_init.main.CopyProp.diff
9+
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
10+
pub fn main() {
11+
mir! (
12+
let x: (isize, );
13+
{
14+
x.0 = 1;
15+
Return()
16+
}
17+
)
18+
}

0 commit comments

Comments
 (0)