summaryrefslogtreecommitdiff
path: root/src/mir/cleanup.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-11-25 10:48:43 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-11-25 10:48:43 +0800
commitef1ee864ef1b793dcd651b12a4132ddb39ac7679 (patch)
tree6dd55da2e8b9e1bf273ff24ede620231405b5134 /src/mir/cleanup.cpp
parent548b498b0c5531efffff6bc7ea3f451716fa5b6a (diff)
downloadmrust-ef1ee864ef1b793dcd651b12a4132ddb39ac7679.tar.gz
MIR Cleanup - Delete any statements including/after use of !
Diffstat (limited to 'src/mir/cleanup.cpp')
-rw-r--r--src/mir/cleanup.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/mir/cleanup.cpp b/src/mir/cleanup.cpp
index 455eef43..fef5d350 100644
--- a/src/mir/cleanup.cpp
+++ b/src/mir/cleanup.cpp
@@ -937,7 +937,21 @@ void MIR_Cleanup(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path,
state.set_cur_stmt( mutator.cur_block, mutator.cur_stmt );
auto& stmt = *it;
- // 1. Visit all LValues for box deref hackery
+ // >> Detect use of `!` as a value
+ ::HIR::TypeRef tmp;
+ if( TU_TEST1(stmt, Assign, .src.is_Borrow()) && state.get_lvalue_type(tmp, stmt.as_Assign().src.as_Borrow().val).m_data.is_Diverge() )
+ DEBUG(state << "Not killing block due to use of `!`, it's being borrowed");
+ else
+ {
+ if( ::MIR::visit::visit_mir_lvalues(stmt, [&](const auto& lv, auto /*vu*/){ return state.get_lvalue_type(tmp, lv).m_data.is_Diverge();}) )
+ {
+ DEBUG(state << "Truncate entire block due to use of `!` as a value - " << stmt);
+ block.statements.erase(it, block.statements.end());
+ block.terminator = ::MIR::Terminator::make_Diverge({});
+ break ;
+ }
+ }
+ // >> Visit all LValues for box deref hackery
TU_MATCHA( (stmt), (se),
(Drop,
MIR_Cleanup_LValue(state, mutator, se.slot);