summaryrefslogtreecommitdiff
path: root/src/mir/from_hir.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-10 23:28:08 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-10 23:28:08 +0800
commit0767462da25193c3e39080e8ffe71ad8c0963d3c (patch)
treec6d9b4571fc27280e8226ee3cf407a4bdb4f8a3d /src/mir/from_hir.cpp
parent66d4dd26a4ecf73d248201850a2d8b560834004a (diff)
downloadmrust-0767462da25193c3e39080e8ffe71ad8c0963d3c.tar.gz
MIR - Handling of diverging statements
Diffstat (limited to 'src/mir/from_hir.cpp')
-rw-r--r--src/mir/from_hir.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 72618f95..3787f4aa 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -544,21 +544,28 @@ namespace {
auto& subnode = node.m_nodes[i];
const Span& sp = subnode->span();
this->visit_node_ptr(subnode);
- m_builder.push_stmt_drop( m_builder.lvalue_or_temp(subnode->m_res_type, m_builder.get_result(sp)) );
+ if( m_builder.block_active() || m_builder.has_result() )
+ {
+ m_builder.push_stmt_drop( m_builder.lvalue_or_temp(subnode->m_res_type, m_builder.get_result(sp)) );
+ }
}
this->visit_node_ptr(node.m_nodes.back());
- auto ret = m_builder.get_result(node.m_nodes.back()->span());
+ //auto ret = m_builder.get_result(node.m_nodes.back()->span());
auto bd = mv$( m_block_stack.back() );
m_block_stack.pop_back();
// Drop all bindings introduced during this block.
- for( auto& var_idx : bd.bindings ) {
- m_builder.push_stmt_drop( ::MIR::LValue::make_Variable(var_idx) );
+ // TODO: This should be done in a more generic manner, allowing for drops on panic/return
+ if( m_builder.block_active() )
+ {
+ for( auto& var_idx : bd.bindings ) {
+ m_builder.push_stmt_drop( ::MIR::LValue::make_Variable(var_idx) );
+ }
}
- m_builder.set_result(node.span(), mv$(ret));
+ //m_builder.set_result(node.span(), mv$(ret));
}
else
{
@@ -1118,8 +1125,11 @@ namespace {
m_builder.set_cur_block(true_branch);
this->visit_node_ptr(node.m_true);
- m_builder.push_stmt_assign( result_val.clone(), m_builder.get_result(node.m_true->span()) );
- m_builder.end_block( ::MIR::Terminator::make_Goto(next_block) );
+ if( m_builder.block_active() )
+ {
+ m_builder.push_stmt_assign( result_val.clone(), m_builder.get_result(node.m_true->span()) );
+ m_builder.end_block( ::MIR::Terminator::make_Goto(next_block) );
+ }
m_builder.set_cur_block(false_branch);
if( node.m_false )