Skip to content

Commit

Permalink
Auto merge of rust-lang#76306 - tmiasko:nrvo-debuginfo, r=ecstatic-morse
Browse files Browse the repository at this point in the history
NRVO: Allow occurrences of the return place in var debug info

The non-use occurrence of the return place in var debug info does not
currently inhibit NRVO optimization, but it will fail assertion in
`visit_place` when optimization is performed.

Relax assertion check to allow the return place in var debug info.

This case might be impossible to hit in optimization pipelines as of
now, but can be encountered in customized mir-opt-level=2 pipeline with
copy propagation disabled. For example in:

```rust
pub fn b(s: String) -> String {
    a(s)
}

#[inline]
pub fn a(s: String) -> String {
    let x = s;
    let y = x;
    y
}
```
  • Loading branch information
bors committed Sep 13, 2020
2 parents dbb73f8 + 0151061 commit 498dab0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/rustc_mir/src/transform/nrvo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_hir::Mutability;
use rustc_index::bit_set::HybridBitSet;
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::visit::{MutVisitor, NonUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{self, BasicBlock, Local, Location};
use rustc_middle::ty::TyCtxt;

Expand Down Expand Up @@ -196,9 +196,10 @@ impl MutVisitor<'tcx> for RenameToReturnPlace<'tcx> {
self.super_terminator(terminator, loc);
}

fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
assert_ne!(*l, mir::RETURN_PLACE);
if *l == self.to_rename {
fn visit_local(&mut self, l: &mut Local, ctxt: PlaceContext, _: Location) {
if *l == mir::RETURN_PLACE {
assert_eq!(ctxt, PlaceContext::NonUse(NonUseContext::VarDebugInfo));
} else if *l == self.to_rename {
*l = mir::RETURN_PLACE;
}
}
Expand Down

0 comments on commit 498dab0

Please sign in to comment.