Skip to content

Commit be9c2d1

Browse files
committed
Bug fixes for flowgraph construction.
1. After recursively processing an ExprWhile, need to pop loop_scopes the same way we do for ExprLoop. 2. Proposed fix for flowgraph handling of ExprInlineAsm: we need to represent the flow into the subexpressions of an `asm!` block.
1 parent 34e3232 commit be9c2d1

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/librustc/middle/cfg/construct.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl<'a> CFGBuilder<'a> {
254254
});
255255
let body_exit = self.block(&**body, cond_exit); // 4
256256
self.add_contained_edge(body_exit, loopback); // 5
257+
self.loop_scopes.pop();
257258
expr_exit
258259
}
259260

@@ -427,8 +428,22 @@ impl<'a> CFGBuilder<'a> {
427428
self.straightline(expr, pred, [e])
428429
}
429430

431+
ast::ExprInlineAsm(ref inline_asm) => {
432+
let inputs = inline_asm.inputs.iter();
433+
let outputs = inline_asm.outputs.iter();
434+
fn extract_expr<A>(&(_, expr): &(A, Gc<ast::Expr>)) -> Gc<ast::Expr> { expr }
435+
let post_inputs = self.exprs(inputs.map(|a| {
436+
debug!("cfg::construct InlineAsm id:{} input:{:?}", expr.id, a);
437+
extract_expr(a)
438+
}), pred);
439+
let post_outputs = self.exprs(outputs.map(|a| {
440+
debug!("cfg::construct InlineAsm id:{} output:{:?}", expr.id, a);
441+
extract_expr(a)
442+
}), post_inputs);
443+
self.add_node(expr.id, [post_outputs])
444+
}
445+
430446
ast::ExprMac(..) |
431-
ast::ExprInlineAsm(..) |
432447
ast::ExprFnBlock(..) |
433448
ast::ExprProc(..) |
434449
ast::ExprLit(..) |
@@ -444,15 +459,22 @@ impl<'a> CFGBuilder<'a> {
444459
func_or_rcvr: Gc<ast::Expr>,
445460
args: &[Gc<ast::Expr>]) -> CFGIndex {
446461
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
447-
self.straightline(call_expr, func_or_rcvr_exit, args)
462+
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
463+
464+
let return_ty = ty::node_id_to_type(self.tcx, call_expr.id);
465+
let fails = ty::type_is_bot(return_ty);
466+
if fails {
467+
self.add_node(ast::DUMMY_NODE_ID, [])
468+
} else {
469+
ret
470+
}
448471
}
449472

450-
fn exprs(&mut self,
451-
exprs: &[Gc<ast::Expr>],
452-
pred: CFGIndex) -> CFGIndex {
473+
fn exprs<I:Iterator<Gc<ast::Expr>>>(&mut self,
474+
mut exprs: I,
475+
pred: CFGIndex) -> CFGIndex {
453476
//! Constructs graph for `exprs` evaluated in order
454-
455-
exprs.iter().fold(pred, |p, &e| self.expr(e, p))
477+
exprs.fold(pred, |p, e| self.expr(e, p))
456478
}
457479

458480
fn opt_expr(&mut self,
@@ -469,7 +491,7 @@ impl<'a> CFGBuilder<'a> {
469491
subexprs: &[Gc<ast::Expr>]) -> CFGIndex {
470492
//! Handles case of an expression that evaluates `subexprs` in order
471493
472-
let subexprs_exit = self.exprs(subexprs, pred);
494+
let subexprs_exit = self.exprs(subexprs.iter().map(|&e|e), pred);
473495
self.add_node(expr.id, [subexprs_exit])
474496
}
475497

0 commit comments

Comments
 (0)