* */
| 57 | * |
| 58 | */ |
| 59 | StatementIf * |
| 60 | StatementIf::make_random(CGContext &cg_context) |
| 61 | { |
| 62 | DEPTH_GUARD_BY_TYPE_RETURN(dtStatementIf, NULL); |
| 63 | FactMgr* fm = get_fact_mgr(&cg_context); |
| 64 | FactVec pre_facts; |
| 65 | Effect pre_effect; |
| 66 | // func_1 hacking, save the env in case we need to re-analyze |
| 67 | if (cg_context.get_current_func()->name == "func_1" && !(cg_context.flags & IN_LOOP)) { |
| 68 | pre_effect = cg_context.get_accum_effect(); |
| 69 | pre_facts = fm->global_facts; |
| 70 | } |
| 71 | cg_context.get_effect_stm().clear(); |
| 72 | Expression *expr = Expression::make_random(cg_context, get_int_type(), NULL, false, !CGOptions::const_as_condition()); |
| 73 | ERROR_GUARD(NULL); |
| 74 | // func_1 hacking, re-analyze for multiple function calls |
| 75 | if (cg_context.get_current_func()->name == "func_1" && !(cg_context.flags & IN_LOOP)) { |
| 76 | if (expr->has_uncertain_call_recursive()) { |
| 77 | fm->makeup_new_var_facts(pre_facts, fm->global_facts); |
| 78 | cg_context.reset_effect_accum(pre_effect); |
| 79 | cg_context.curr_blk = cg_context.get_current_block(); |
| 80 | bool ok = expr->visit_facts(pre_facts, cg_context); |
| 81 | if (!ok) { |
| 82 | // print_facts(pre_facts); |
| 83 | // expr->indented_output(cout, 0); |
| 84 | } |
| 85 | assert(ok); |
| 86 | fm->global_facts = pre_facts; |
| 87 | } |
| 88 | } |
| 89 | Effect eff = cg_context.get_effect_stm(); |
| 90 | |
| 91 | // this will save global_facts to map_facts_in[if_true], and update |
| 92 | // facts for new variables created while generating if_true |
| 93 | Block *if_true = Block::make_random(cg_context); |
| 94 | ERROR_GUARD_AND_DEL1(NULL, expr); |
| 95 | |
| 96 | // generate false branch with the same env as true branch |
| 97 | fm->global_facts = fm->map_facts_in[if_true]; |
| 98 | Block *if_false = Block::make_random(cg_context); |
| 99 | ERROR_GUARD_AND_DEL2(NULL, expr, if_true); |
| 100 | |
| 101 | StatementIf* si = new StatementIf(cg_context.get_current_block(), *expr, *if_true, *if_false); |
| 102 | // compute accumulated effect for this statement |
| 103 | si->set_accumulated_effect_after_block(eff, if_true, cg_context); |
| 104 | si->set_accumulated_effect_after_block(eff, if_false, cg_context); |
| 105 | return si; |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * |
nothing calls this directly
no test coverage detected