2 * Copyright (C) 2014 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 #include "smatch_extra.h"
22 static int my_return_id
;
26 int is_impossible_path(void)
28 if (get_state(my_id
, "impossible", NULL
) == &impossible
)
33 static void handle_compare(struct expression
*left
, int op
, struct expression
*right
)
35 int true_impossible
= 0;
36 int false_impossible
= 0;
38 if (!possibly_true(left
, op
, right
))
40 if (!possibly_false(left
, op
, right
))
43 if (!true_impossible
&& !false_impossible
)
46 set_true_false_states(my_id
, "impossible", NULL
,
47 true_impossible
? &impossible
: &undefined
,
48 false_impossible
? &impossible
: &undefined
);
53 set_true_false_states(my_return_id
, "impossible", NULL
,
54 true_impossible
? &impossible
: &undefined
,
55 false_impossible
? &impossible
: &undefined
);
58 static void match_condition(struct expression
*expr
)
60 if (expr
->type
== EXPR_COMPARE
)
61 handle_compare(expr
->left
, expr
->op
, expr
->right
);
63 handle_compare(expr
, SPECIAL_NOTEQUAL
, zero_expr());
66 static void print_impossible_return(int return_id
, char *return_ranges
, struct expression
*expr
)
68 if (get_state(my_return_id
, "impossible", NULL
) == &impossible
) {
70 sm_msg("impossible return. return_id = %d return ranges = %s", return_id
, return_ranges
);
71 sql_insert_return_states(return_id
, return_ranges
, CULL_PATH
, -1, "", "");
75 void register_impossible(int id
)
79 add_hook(&match_condition
, CONDITION_HOOK
);
82 void register_impossible_return(int id
)
86 add_split_return_callback(&print_impossible_return
);