Print this page
new smatch

*** 56,66 **** * merge_sm_state() sets ->left and ->right. (These are the states which were * merged to form the current state.) * a pool: a pool is an slist that has been merged with another slist. */ - #include <sys/time.h> #include <time.h> #include "smatch.h" #include "smatch_slist.h" #include "smatch_extra.h" --- 56,65 ----
*** 69,78 **** --- 68,82 ---- bool implications_off; #define implied_debug 0 #define DIMPLIED(msg...) do { if (implied_debug) printf(msg); } while (0) + bool debug_implied(void) + { + return implied_debug; + } + /* * tmp_range_list(): * It messes things up to free range list allocations. This helper fuction * lets us reuse memory instead of doing new allocations. */
*** 296,312 **** struct state_list **checked, int *mixed, struct sm_state *gate_sm, struct timeval *start_time) { int free_checked = 0; struct state_list *checked_states = NULL; ! struct timeval now; if (!sm) return; gettimeofday(&now, NULL); ! if (now.tv_usec - start_time->tv_usec > 1000000) { if (implied_debug) { sm_msg("debug: %s: implications taking too long. (%s %s %s)", __func__, sm->state->name, show_special(comparison), show_rl(rl)); } if (mixed) --- 300,317 ---- struct state_list **checked, int *mixed, struct sm_state *gate_sm, struct timeval *start_time) { int free_checked = 0; struct state_list *checked_states = NULL; ! struct timeval now, diff; if (!sm) return; gettimeofday(&now, NULL); ! timersub(&now, start_time, &diff); ! if (diff.tv_sec >= 1) { if (implied_debug) { sm_msg("debug: %s: implications taking too long. (%s %s %s)", __func__, sm->state->name, show_special(comparison), show_rl(rl)); } if (mixed)
*** 449,466 **** { struct sm_state *ret = NULL; struct sm_state *left; struct sm_state *right; int removed = 0; ! struct timeval now; if (!sm) return NULL; if (*bail) return NULL; gettimeofday(&now, NULL); ! if (now.tv_usec - start->tv_usec > 3000000) { DIMPLIED("%s: implications taking too long: %s\n", __func__, sm_state_info(sm)); *bail = 1; return NULL; } if ((*recurse_cnt)++ > RECURSE_LIMIT) { --- 454,472 ---- { struct sm_state *ret = NULL; struct sm_state *left; struct sm_state *right; int removed = 0; ! struct timeval now, diff; if (!sm) return NULL; if (*bail) return NULL; gettimeofday(&now, NULL); ! timersub(&now, start, &diff); ! if (diff.tv_sec >= 3) { DIMPLIED("%s: implications taking too long: %s\n", __func__, sm_state_info(sm)); *bail = 1; return NULL; } if ((*recurse_cnt)++ > RECURSE_LIMIT) {
*** 597,614 **** *true_states = filter_stack(sm, pre_stree, false_stack, true_stack); DIMPLIED("filtering false stack.\n"); *false_states = filter_stack(sm, pre_stree, true_stack, false_stack); free_slist(&true_stack); free_slist(&false_stack); - if (implied_debug) { - printf("These are the implied states for the true path: (%s (%s) %s %s)\n", - sm->name, sm->state->name, show_special(comparison), show_rl(rl)); - __print_stree(*true_states); - printf("These are the implied states for the false path: (%s (%s) %s %s)\n", - sm->name, sm->state->name, show_special(comparison), show_rl(rl)); - __print_stree(*false_states); - } gettimeofday(&time_after, NULL); sec = time_after.tv_sec - time_before.tv_sec; if (option_timeout && sec > option_timeout) { sm_perror("Function too hairy. Ignoring implications after %d seconds.", sec); --- 603,612 ----
*** 795,804 **** --- 793,808 ---- static int handled_by_extra_states(struct expression *expr, struct stree **implied_true, struct stree **implied_false) { + sval_t sval; + + /* If the expression is known then it has no implications. */ + if (get_implied_value(expr, &sval)) + return true; + if (expr->type == EXPR_COMPARE) return handle_comparison(expr, implied_true, implied_false); else return handle_zero_comparison(expr, implied_true, implied_false); }
*** 881,890 **** --- 885,906 ---- static void set_implied_states(struct expression *expr) { struct sm_state *sm; + if (implied_debug && + (expr || saved_implied_true || saved_implied_false)) { + char *name; + + name = expr_to_str(expr); + printf("These are the implied states for the true path: (%s)\n", name); + __print_stree(saved_implied_true); + printf("These are the implied states for the false path: (%s)\n", name); + __print_stree(saved_implied_false); + free_string(name); + } + FOR_EACH_SM(saved_implied_true, sm) { __set_true_false_sm(sm, NULL); } END_FOR_EACH_SM(sm); free_stree(&saved_implied_true);