Skip to content

Commit a763b96

Browse files
NRVO pass for acyclic CFGs
1 parent 5179ebe commit a763b96

File tree

6 files changed

+658
-7
lines changed

6 files changed

+658
-7
lines changed

src/librustc_middle/mir/interpret/error.rs

-3
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,6 @@ pub enum UndefinedBehaviorInfo {
368368
InvalidUndefBytes(Option<Pointer>),
369369
/// Working with a local that is not currently live.
370370
DeadLocal,
371-
/// Trying to read from the return place of a function.
372-
ReadFromReturnPlace,
373371
}
374372

375373
impl fmt::Debug for UndefinedBehaviorInfo {
@@ -431,7 +429,6 @@ impl fmt::Debug for UndefinedBehaviorInfo {
431429
"using uninitialized data, but this operation requires initialized memory"
432430
),
433431
DeadLocal => write!(f, "accessing a dead local variable"),
434-
ReadFromReturnPlace => write!(f, "tried to read from the return place"),
435432
}
436433
}
437434
}

src/librustc_mir/interpret/operand.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
445445
layout: Option<TyAndLayout<'tcx>>,
446446
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
447447
let base_op = match place.local {
448-
mir::RETURN_PLACE => throw_ub!(ReadFromReturnPlace),
448+
mir::RETURN_PLACE => {
449+
if let Some(place) = self.frame().return_place {
450+
self.place_to_op(place)?
451+
} else {
452+
// Tried to access return place, but the function cannot return
453+
throw_ub!(Unreachable)
454+
}
455+
}
449456
local => {
450457
// Do not use the layout passed in as argument if the base we are looking at
451458
// here is not the entire place.

src/librustc_mir/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Rust MIR: a lowered representation of Rust.
2626
#![feature(trait_alias)]
2727
#![feature(option_expect_none)]
2828
#![feature(or_patterns)]
29+
#![feature(bindings_after_at)]
2930
#![recursion_limit = "256"]
3031

3132
#[macro_use]

0 commit comments

Comments
 (0)