diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-31 21:37:21 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-09-06 01:37:51 +0200 |
| commit | e811962ea0f56da569c6504ac150b357b069b11a (patch) | |
| tree | f88c8c0014c608cba560f7d8c242fd9ad3301623 /linearize.c | |
| parent | b422403a2bdaba8f0b4804c97f35141b27fb7a08 (diff) | |
| download | sparse-dev-e811962ea0f56da569c6504ac150b357b069b11a.tar.gz | |
extract add_return() from linearize_return()
This will allow to reuse this code to generate valid IR
in the case of a missing return statement.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'linearize.c')
| -rw-r--r-- | linearize.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/linearize.c b/linearize.c index d6647e44..53d66ffa 100644 --- a/linearize.c +++ b/linearize.c @@ -1980,6 +1980,21 @@ static pseudo_t linearize_compound_statement(struct entrypoint *ep, struct state return pseudo; } +static void add_return(struct entrypoint *ep, struct basic_block *bb, struct symbol *ctype, pseudo_t src) +{ + struct instruction *phi_node = first_instruction(bb->insns); + pseudo_t phi; + if (!phi_node) { + phi_node = alloc_typed_instruction(OP_PHI, ctype); + phi_node->target = alloc_pseudo(phi_node); + phi_node->bb = bb; + add_instruction(&bb->insns, phi_node); + } + phi = alloc_phi(ep->active, src, ctype); + phi->ident = &return_ident; + use_pseudo(phi_node, phi, add_pseudo(&phi_node->phi_list, phi)); +} + static pseudo_t linearize_fn_statement(struct entrypoint *ep, struct statement *stmt) { struct instruction *phi_node; @@ -2157,17 +2172,7 @@ static pseudo_t linearize_return(struct entrypoint *ep, struct statement *stmt) pseudo_t src = linearize_expression(ep, expr); active = ep->active; if (active && src != VOID) { - struct instruction *phi_node = first_instruction(bb_return->insns); - pseudo_t phi; - if (!phi_node) { - phi_node = alloc_typed_instruction(OP_PHI, expr->ctype); - phi_node->target = alloc_pseudo(phi_node); - phi_node->bb = bb_return; - add_instruction(&bb_return->insns, phi_node); - } - phi = alloc_phi(active, src, expr->ctype); - phi->ident = &return_ident; - use_pseudo(phi_node, phi, add_pseudo(&phi_node->phi_list, phi)); + add_return(ep, bb_return, expr->ctype, src); } add_goto(ep, bb_return); return VOID; |
