Skip to content

Commit

Permalink
Bug fixes for flowgraph construction.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pnkfelix committed Jun 16, 2014
1 parent 7ec7805 commit ef0990a
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ impl<'a> CFGBuilder<'a> {
});
let body_exit = self.block(&**body, cond_exit); // 4
self.add_contained_edge(body_exit, loopback); // 5
self.loop_scopes.pop();
expr_exit
}

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

ast::ExprInlineAsm(ref inline_asm) => {
let inputs = inline_asm.inputs.iter();
let outputs = inline_asm.outputs.iter();
fn extract_expr<A>(&(_, expr): &(A, Gc<ast::Expr>)) -> Gc<ast::Expr> { expr }
let post_inputs = self.exprs(inputs.map(|a| {
debug!("cfg::construct InlineAsm id:{} input:{:?}", expr.id, a);
extract_expr(a)
}), pred);
let post_outputs = self.exprs(outputs.map(|a| {
debug!("cfg::construct InlineAsm id:{} output:{:?}", expr.id, a);
extract_expr(a)
}), post_inputs);
self.add_node(expr.id, [post_outputs])
}

ast::ExprMac(..) |
ast::ExprInlineAsm(..) |
ast::ExprFnBlock(..) |
ast::ExprProc(..) |
ast::ExprLit(..) |
Expand All @@ -444,15 +459,22 @@ impl<'a> CFGBuilder<'a> {
func_or_rcvr: Gc<ast::Expr>,
args: &[Gc<ast::Expr>]) -> CFGIndex {
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
self.straightline(call_expr, func_or_rcvr_exit, args)
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);

let return_ty = ty::node_id_to_type(self.tcx, call_expr.id);
let fails = ty::type_is_bot(return_ty);
if fails {
self.add_node(ast::DUMMY_NODE_ID, [])
} else {
ret
}
}

fn exprs(&mut self,
exprs: &[Gc<ast::Expr>],
pred: CFGIndex) -> CFGIndex {
fn exprs<I:Iterator<Gc<ast::Expr>>>(&mut self,
mut exprs: I,
pred: CFGIndex) -> CFGIndex {
//! Constructs graph for `exprs` evaluated in order

exprs.iter().fold(pred, |p, &e| self.expr(e, p))
exprs.fold(pred, |p, e| self.expr(e, p))
}

fn opt_expr(&mut self,
Expand All @@ -469,7 +491,7 @@ impl<'a> CFGBuilder<'a> {
subexprs: &[Gc<ast::Expr>]) -> CFGIndex {
//! Handles case of an expression that evaluates `subexprs` in order

let subexprs_exit = self.exprs(subexprs, pred);
let subexprs_exit = self.exprs(subexprs.iter().map(|&e|e), pred);
self.add_node(expr.id, [subexprs_exit])
}

Expand Down

0 comments on commit ef0990a

Please sign in to comment.