提交 aed0c9c9 编写于 作者: D Djzin

use lazy cached unreachable block - assign it to the function's closing brace

上级 829b7033
......@@ -205,7 +205,7 @@ pub fn perform_test(&mut self,
if let Some(otherwise_block) = otherwise_block {
targets.push(otherwise_block);
} else {
let unreachable_block = self.cfg.start_new_block();
let unreachable_block = self.unreachable_block();
targets.push(unreachable_block);
target_blocks.push(unreachable_block);
}
......
......@@ -306,6 +306,8 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
cached_resume_block: Option<BasicBlock>,
/// cached block with the RETURN terminator
cached_return_block: Option<BasicBlock>,
/// cached block with the UNREACHABLE terminator
cached_unreachable_block: Option<BasicBlock>,
}
struct CFG<'tcx> {
......@@ -399,6 +401,11 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
TerminatorKind::Goto { target: return_block });
builder.cfg.terminate(return_block, source_info,
TerminatorKind::Return);
// Attribute any unreachable codepaths to the function's closing brace
if let Some(unreachable_block) = builder.cached_unreachable_block {
builder.cfg.terminate(unreachable_block, source_info,
TerminatorKind::Unreachable);
}
return_block.unit()
}));
assert_eq!(block, builder.return_block());
......@@ -501,7 +508,8 @@ fn new(hir: Cx<'a, 'gcx, 'tcx>,
var_indices: NodeMap(),
unit_temp: None,
cached_resume_block: None,
cached_return_block: None
cached_return_block: None,
cached_unreachable_block: None,
};
assert_eq!(builder.cfg.start_new_block(), START_BLOCK);
......@@ -630,6 +638,17 @@ fn return_block(&mut self) -> BasicBlock {
}
}
}
fn unreachable_block(&mut self) -> BasicBlock {
match self.cached_unreachable_block {
Some(ub) => ub,
None => {
let ub = self.cfg.start_new_block();
self.cached_unreachable_block = Some(ub);
ub
}
}
}
}
///////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册