From b3157aba51689d13d60799e7e2cd1612af89b6e2 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 25 Feb 2009 09:00:49 +0300 Subject: [PATCH] New function harmonize_states() harmonize_states() makes sure that each implied true state matches an implied false state and that they are different. Setting the implied states currently erases the ->possible and ->pools lists so it's a bad idea to do it for no reason. Plus doing it for no reason makes the --debug output longer. If the there is only a true state and not a false state then when we or the true and false states it gets set to &undefined. &state + NULL => &undefined. Signed-off-by: Dan Carpenter --- smatch_implied.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/smatch_implied.c b/smatch_implied.c index 6e5d42a8..40ab81db 100644 --- a/smatch_implied.c +++ b/smatch_implied.c @@ -81,8 +81,38 @@ static struct state_list *get_eq_neq_filtered(struct sm_state *sm_state, } /* - * This condition hook is very connected to smatch_extra.c. + * We have to check that we have both a true and false state and that the + * two are different. Otherwise compound conditions end up giving &undefined + * a lot. */ +void harmonize_states(struct state_list **imp_true, struct state_list **imp_false) +{ + struct sm_state *sm_true; + struct sm_state *sm_false; + + PREPARE_PTR_LIST(*imp_true, sm_true); + PREPARE_PTR_LIST(*imp_false, sm_false); + for (;;) { + if (!sm_true && !sm_false) + break; + if (cmp_tracker(sm_true, sm_false) < 0) { + DELETE_CURRENT_PTR(sm_true); + NEXT_PTR_LIST(sm_true); + } else if (cmp_tracker(sm_true, sm_false) == 0) { + if (sm_true->state == sm_false->state) { + DELETE_CURRENT_PTR(sm_true); + DELETE_CURRENT_PTR(sm_false); + } + NEXT_PTR_LIST(sm_true); + NEXT_PTR_LIST(sm_false); + } else { + DELETE_CURRENT_PTR(sm_false); + NEXT_PTR_LIST(sm_false); + } + } + FINISH_PTR_LIST(sm_false); + FINISH_PTR_LIST(sm_true); +} void __implied_states_hook(struct expression *expr) { @@ -102,6 +132,7 @@ void __implied_states_hook(struct expression *expr) return; implied_true = get_eq_neq_filtered(state, NOTEQUALS, 0); implied_false = get_eq_neq_filtered(state, EQUALS, 0); + harmonize_states(&implied_true, &implied_false); if (debug_states) { printf("Setting the following implied states for the true path.\n"); __print_slist(implied_true); -- 2.11.4.GIT