summaryrefslogtreecommitdiff
path: root/src/mir/helpers.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-04-28 20:16:40 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-04-28 20:16:40 +0800
commit70e74a7c8b293326c1df5ed02e1156caa8fd741c (patch)
treecf5181e64950ae1ec5fbaf567398b06ff5381afe /src/mir/helpers.cpp
parent8d08853331807ad28058487e875e2f9adbfa92da (diff)
downloadmrust-70e74a7c8b293326c1df5ed02e1156caa8fd741c.tar.gz
MIR Helpers - Minor fix to lifetime calculation
Diffstat (limited to 'src/mir/helpers.cpp')
-rw-r--r--src/mir/helpers.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/mir/helpers.cpp b/src/mir/helpers.cpp
index 839cfe71..cbd189bf 100644
--- a/src/mir/helpers.cpp
+++ b/src/mir/helpers.cpp
@@ -529,13 +529,16 @@ void MIR_Helper_GetLifetimes_DetermineValueLifetime(::MIR::TypeResolve& state, c
for(size_t bb_idx = 0; bb_idx < fcn.blocks.size(); bb_idx ++)
{
auto assigned_lvalue = [&](size_t bb_idx, size_t stmt_idx, const ::MIR::LValue& lv) {
+ // NOTE: Fills the first statement after running, just to ensure that any assigned value has _a_ lifetime
if( const auto* de = lv.opt_Variable() )
{
MIR_Helper_GetLifetimes_DetermineValueLifetime(state, fcn, bb_idx, stmt_idx, lv, block_offsets, variable_lifetimes[*de]);
+ variable_lifetimes[*de].fill(block_offsets, bb_idx, stmt_idx, stmt_idx);
}
else if( const auto* de = lv.opt_Temporary() )
{
MIR_Helper_GetLifetimes_DetermineValueLifetime(state, fcn, bb_idx, stmt_idx, lv, block_offsets, temporary_lifetimes[de->idx]);
+ temporary_lifetimes[de->idx].fill(block_offsets, bb_idx, stmt_idx, stmt_idx);
}
else
{
@@ -935,6 +938,7 @@ void MIR_Helper_GetLifetimes_DetermineValueLifetime(
// TODO: Have a bitmap of visited statements. If a visted statement is hit, stop the current state
// - Use the same rules as loopback.
+ // Fill the first statement, to ensure that there is at least one bit set.
runner.run_block(bb_idx, stmt_idx, State(block_offsets, vl, bb_idx, stmt_idx));
while( ! runner.m_states_to_do.empty() )
@@ -955,6 +959,13 @@ void MIR_Helper_GetLifetimes_DetermineValueLifetime(
state.finalise(0);
continue ;
}
+ else if( state.is_borrowed() )
+ {
+ DEBUG("Looped (borrowed)");
+ state.mark_read(0);
+ state.finalise(0);
+ continue ;
+ }
else
{
// Put this state elsewhere and check if the variable is known valid at that point.