diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-03-12 12:57:43 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-03-12 12:57:43 +0800 |
commit | bf689be1b4c40c90c257595a0d884b4a4674a8f3 (patch) | |
tree | d787aa9011715d724a2609ee7b53aadc9a1728a2 /src/mir/from_hir.cpp | |
parent | 7a30e6e65bda212ffc09807bfacb8db3b815bc5d (diff) | |
download | mrust-bf689be1b4c40c90c257595a0d884b4a4674a8f3.tar.gz |
MIR Gen - Fix Use-after-free when let borrows a temporary
Diffstat (limited to 'src/mir/from_hir.cpp')
-rw-r--r-- | src/mir/from_hir.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index 60ac0275..a9a40b58 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -381,6 +381,19 @@ namespace { auto& subnode = node.m_nodes[i]; const Span& sp = subnode->span(); + // Let statements don't generate a new temporary scope + if( dynamic_cast<::HIR::ExprNode_Let*>(subnode.get()) ) { + this->visit_node_ptr(subnode); + if( ! m_builder.block_active() ) { + m_builder.set_cur_block( m_builder.new_bb_unlinked() ); + diverged = true; + } + else { + m_builder.get_result(sp); + } + continue ; + } + auto stmt_scope = m_builder.new_scope_temp(sp); this->visit_node_ptr(subnode); |