Print this page
11506 smatch resync
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/smatch_imaginary_absolute.c
+++ new/usr/src/tools/smatch/src/smatch_imaginary_absolute.c
1 1 /*
2 2 * Copyright (C) 2016 Oracle.
3 3 *
4 4 * This program is free software; you can redistribute it and/or
5 5 * modify it under the terms of the GNU General Public License
6 6 * as published by the Free Software Foundation; either version 2
7 7 * of the License, or (at your option) any later version.
8 8 *
9 9 * This program is distributed in the hope that it will be useful,
10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 * GNU General Public License for more details.
13 13 *
14 14 * You should have received a copy of the GNU General Public License
15 15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16 16 */
17 17
18 18 /*
19 19 * Say you have a condition like:
20 20 *
21 21 * if (foo < 0)
22 22 * return foo;
23 23 *
24 24 * But we actually know that foo is zero. Then in smatch_extra.c we set "foo"
25 25 * to the empty state and then for the return statement we say that "foo" is
26 26 * s32min-s32max because we can't return the empty state.
27 27 *
28 28 * This file is supposed to provide an alternative to say that actually "foo" is
29 29 * less than zero.
30 30 *
31 31 */
32 32
33 33 #include "smatch.h"
34 34 #include "smatch_slist.h"
35 35 #include "smatch_extra.h"
36 36
37 37 static int my_id;
38 38
39 39 static struct smatch_state *empty_state(struct sm_state *sm)
40 40 {
41 41 return alloc_estate_empty();
42 42 }
43 43
44 44 struct smatch_state *merge_is_empty(struct smatch_state *s1, struct smatch_state *s2)
45 45 {
↓ open down ↓ |
45 lines elided |
↑ open up ↑ |
46 46 return alloc_estate_empty();
47 47 }
48 48
49 49 static void reset(struct sm_state *sm, struct expression *mod_expr)
50 50 {
51 51 set_state(my_id, sm->name, sm->sym, alloc_estate_empty());
52 52 }
53 53
54 54 void __save_imaginary_state(struct expression *expr, struct range_list *true_rl, struct range_list *false_rl)
55 55 {
56 + if (__in_pre_condition)
57 + return;
56 58 set_true_false_states_expr(my_id, expr, alloc_estate_rl(true_rl), alloc_estate_rl(false_rl));
57 59 }
58 60
59 61 int get_imaginary_absolute(struct expression *expr, struct range_list **rl)
60 62 {
61 63 struct smatch_state *state;
62 64
63 65 *rl = NULL;
64 66
65 67 state = get_state_expr(my_id, expr);
66 68 if (!state || !estate_rl(state))
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
67 69 return 0;
68 70
69 71 *rl = estate_rl(state);
70 72 return 1;
71 73 }
72 74
73 75 void register_imaginary_absolute(int id)
74 76 {
75 77 my_id = id;
76 78
79 + set_dynamic_states(my_id);
77 80 add_unmatched_state_hook(my_id, &empty_state);
78 81 add_merge_hook(my_id, &merge_is_empty);
79 82 add_modification_hook(my_id, &reset);
80 83 }
81 84
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX