summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2019-10-20 21:58:51 +0800
committerJohn Hodge <tpg@ucc.asn.au>2019-10-20 21:58:51 +0800
commit06c3d8935a30ceac3715b7a3fcca586538adb684 (patch)
tree5ed99b869cdc521530d5bf7a4680ee0f5e9ade9f
parent76ae7a61ef67cf6f8737b39b71e752e982c5f815 (diff)
downloadmrust-06c3d8935a30ceac3715b7a3fcca586538adb684.tar.gz
MIR Optimise - Fix a mis-optimisatio when there's &mut-s around
-rw-r--r--src/mir/optimise.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/mir/optimise.cpp b/src/mir/optimise.cpp
index 183894c5..04ba8470 100644
--- a/src/mir/optimise.cpp
+++ b/src/mir/optimise.cpp
@@ -1645,10 +1645,13 @@ bool MIR_Optimise_DeTemporary_SingleSetAndUse(::MIR::TypeResolve& state, ::MIR::
// Move the usage up to original assignment (if destination isn't invalidated)
const auto& dst = use_bb.statements[slot.use_loc.stmt_idx].as_Assign().dst;
+ // TODO: If the destination slot was ever borrowed mutably, don't move.
+ // - Maybe, if there's a drop skip? (as the drop could be &mut to the target value)
+
// - Iterate the path(s) between the two statements to check if the destination would be invalidated
// > The iterate function doesn't (yet) support following BB chains, so assume invalidated if over a jump.
bool invalidated = IterPathRes::Complete != iter_path(fcn, slot.set_loc, slot.use_loc,
- [&](auto loc, const auto& stmt)->bool{ return check_invalidates_lvalue(stmt, dst, /*also_read=*/true); },
+ [&](auto loc, const auto& stmt)->bool{ return stmt.is_Drop() || check_invalidates_lvalue(stmt, dst, /*also_read=*/true); },
[&](auto loc, const auto& term)->bool{ return check_invalidates_lvalue(term, dst, /*also_read=*/true); }
);
if( !invalidated )