36 struct range_list *value_ranges;
37 struct related_list *rlist;
38
39 if (estates_equiv(s1, s2))
40 return s1;
41
42 value_ranges = rl_union(estate_rl(s1), estate_rl(s2));
43 tmp = alloc_estate_rl(value_ranges);
44 rlist = get_shared_relations(estate_related(s1), estate_related(s2));
45 set_related(tmp, rlist);
46
47 if ((estate_has_hard_max(s1) && (!estate_rl(s2) || estate_has_hard_max(s2))) ||
48 (estate_has_hard_max(s2) && (!estate_rl(s1) || estate_has_hard_max(s1))))
49 estate_set_hard_max(tmp);
50
51 estate_set_fuzzy_max(tmp, sval_max(estate_get_fuzzy_max(s1), estate_get_fuzzy_max(s2)));
52
53 if (estate_capped(s1) && estate_capped(s2))
54 estate_set_capped(tmp);
55
56 return tmp;
57 }
58
59 struct data_info *get_dinfo(struct smatch_state *state)
60 {
61 if (!state)
62 return NULL;
63 return (struct data_info *)state->data;
64 }
65
66 struct range_list *estate_rl(struct smatch_state *state)
67 {
68 if (!state)
69 return NULL;
70 return get_dinfo(state)->value_ranges;
71 }
72
73 struct related_list *estate_related(struct smatch_state *state)
74 {
75 if (!state)
99 return;
100 get_dinfo(state)->fuzzy_max = fuzzy_max;
101 }
102
103 void estate_copy_fuzzy_max(struct smatch_state *new, struct smatch_state *old)
104 {
105 if (!estate_has_fuzzy_max(old))
106 return;
107 estate_set_fuzzy_max(new, estate_get_fuzzy_max(old));
108 }
109
110 void estate_clear_fuzzy_max(struct smatch_state *state)
111 {
112 sval_t empty = {};
113
114 get_dinfo(state)->fuzzy_max = empty;
115 }
116
117 int estate_has_hard_max(struct smatch_state *state)
118 {
119 if (!state)
120 return 0;
121 return get_dinfo(state)->hard_max;
122 }
123
124 void estate_set_hard_max(struct smatch_state *state)
125 {
126 get_dinfo(state)->hard_max = 1;
127 }
128
129 void estate_clear_hard_max(struct smatch_state *state)
130 {
131 get_dinfo(state)->hard_max = 0;
132 }
133
134 int estate_get_hard_max(struct smatch_state *state, sval_t *sval)
135 {
136 if (!state || !get_dinfo(state)->hard_max || !estate_rl(state))
137 return 0;
138 *sval = rl_max(estate_rl(state));
139 return 1;
140 }
141
142 bool estate_capped(struct smatch_state *state)
143 {
144 if (!state)
145 return false;
146 /* impossible states are capped */
147 if (!estate_rl(state))
148 return true;
149 return get_dinfo(state)->capped;
150 }
151
152 void estate_set_capped(struct smatch_state *state)
153 {
154 get_dinfo(state)->capped = true;
155 }
156
157 sval_t estate_min(struct smatch_state *state)
158 {
159 return rl_min(estate_rl(state));
160 }
161
162 sval_t estate_max(struct smatch_state *state)
163 {
164 return rl_max(estate_rl(state));
165 }
166
167 struct symbol *estate_type(struct smatch_state *state)
168 {
169 return rl_max(estate_rl(state)).type;
170 }
171
172 static int rlists_equiv(struct related_list *one, struct related_list *two)
173 {
174 struct relation *one_rel;
175 struct relation *two_rel;
176
187 return 0;
188 NEXT_PTR_LIST(one_rel);
189 NEXT_PTR_LIST(two_rel);
190 }
191 FINISH_PTR_LIST(two_rel);
192 FINISH_PTR_LIST(one_rel);
193
194 return 1;
195 }
196
197 int estates_equiv(struct smatch_state *one, struct smatch_state *two)
198 {
199 if (!one || !two)
200 return 0;
201 if (one == two)
202 return 1;
203 if (!rlists_equiv(estate_related(one), estate_related(two)))
204 return 0;
205 if (estate_capped(one) != estate_capped(two))
206 return 0;
207 if (strcmp(one->name, two->name) == 0)
208 return 1;
209 return 0;
210 }
211
212 int estate_is_whole(struct smatch_state *state)
213 {
214 return is_whole_rl(estate_rl(state));
215 }
216
217 int estate_is_empty(struct smatch_state *state)
218 {
219 return state && !estate_rl(state);
220 }
221
222 int estate_is_unknown(struct smatch_state *state)
223 {
224 if (!estate_is_whole(state))
225 return 0;
226 if (estate_related(state))
227 return 0;
228 if (estate_has_fuzzy_max(state))
229 return 0;
230 return 1;
231 }
232
233 int estate_get_single_value(struct smatch_state *state, sval_t *sval)
234 {
235 sval_t min, max;
236
237 min = rl_min(estate_rl(state));
238 max = rl_max(estate_rl(state));
239 if (sval_cmp(min, max) != 0)
240 return 0;
241 *sval = min;
242 return 1;
243 }
244
245 static struct data_info *alloc_dinfo(void)
246 {
247 struct data_info *ret;
248
249 ret = __alloc_data_info(0);
250 memset(ret, 0, sizeof(*ret));
251 return ret;
252 }
253
254 static struct data_info *alloc_dinfo_range(sval_t min, sval_t max)
255 {
256 struct data_info *ret;
|
36 struct range_list *value_ranges;
37 struct related_list *rlist;
38
39 if (estates_equiv(s1, s2))
40 return s1;
41
42 value_ranges = rl_union(estate_rl(s1), estate_rl(s2));
43 tmp = alloc_estate_rl(value_ranges);
44 rlist = get_shared_relations(estate_related(s1), estate_related(s2));
45 set_related(tmp, rlist);
46
47 if ((estate_has_hard_max(s1) && (!estate_rl(s2) || estate_has_hard_max(s2))) ||
48 (estate_has_hard_max(s2) && (!estate_rl(s1) || estate_has_hard_max(s1))))
49 estate_set_hard_max(tmp);
50
51 estate_set_fuzzy_max(tmp, sval_max(estate_get_fuzzy_max(s1), estate_get_fuzzy_max(s2)));
52
53 if (estate_capped(s1) && estate_capped(s2))
54 estate_set_capped(tmp);
55
56 if (estate_treat_untagged(s1) && estate_treat_untagged(s2))
57 estate_set_treat_untagged(tmp);
58
59 return tmp;
60 }
61
62 struct data_info *get_dinfo(struct smatch_state *state)
63 {
64 if (!state)
65 return NULL;
66 return (struct data_info *)state->data;
67 }
68
69 struct range_list *estate_rl(struct smatch_state *state)
70 {
71 if (!state)
72 return NULL;
73 return get_dinfo(state)->value_ranges;
74 }
75
76 struct related_list *estate_related(struct smatch_state *state)
77 {
78 if (!state)
102 return;
103 get_dinfo(state)->fuzzy_max = fuzzy_max;
104 }
105
106 void estate_copy_fuzzy_max(struct smatch_state *new, struct smatch_state *old)
107 {
108 if (!estate_has_fuzzy_max(old))
109 return;
110 estate_set_fuzzy_max(new, estate_get_fuzzy_max(old));
111 }
112
113 void estate_clear_fuzzy_max(struct smatch_state *state)
114 {
115 sval_t empty = {};
116
117 get_dinfo(state)->fuzzy_max = empty;
118 }
119
120 int estate_has_hard_max(struct smatch_state *state)
121 {
122 if (!state || !estate_rl(state))
123 return 0;
124 return get_dinfo(state)->hard_max;
125 }
126
127 void estate_set_hard_max(struct smatch_state *state)
128 {
129 get_dinfo(state)->hard_max = 1;
130 }
131
132 void estate_clear_hard_max(struct smatch_state *state)
133 {
134 get_dinfo(state)->hard_max = 0;
135 }
136
137 int estate_get_hard_max(struct smatch_state *state, sval_t *sval)
138 {
139 if (!state || !get_dinfo(state)->hard_max || !estate_rl(state))
140 return 0;
141 *sval = rl_max(estate_rl(state));
142 return 1;
143 }
144
145 bool estate_capped(struct smatch_state *state)
146 {
147 if (!state)
148 return false;
149 /* impossible states are capped */
150 if (!estate_rl(state))
151 return true;
152 return get_dinfo(state)->capped;
153 }
154
155 void estate_set_capped(struct smatch_state *state)
156 {
157 get_dinfo(state)->capped = true;
158 }
159
160 bool estate_treat_untagged(struct smatch_state *state)
161 {
162 if (!state)
163 return false;
164
165 /* impossible states are capped */
166 if (!estate_rl(state))
167 return true;
168
169 return get_dinfo(state)->treat_untagged;
170 }
171
172 void estate_set_treat_untagged(struct smatch_state *state)
173 {
174 get_dinfo(state)->treat_untagged = true;
175 }
176
177 sval_t estate_min(struct smatch_state *state)
178 {
179 return rl_min(estate_rl(state));
180 }
181
182 sval_t estate_max(struct smatch_state *state)
183 {
184 return rl_max(estate_rl(state));
185 }
186
187 struct symbol *estate_type(struct smatch_state *state)
188 {
189 return rl_max(estate_rl(state)).type;
190 }
191
192 static int rlists_equiv(struct related_list *one, struct related_list *two)
193 {
194 struct relation *one_rel;
195 struct relation *two_rel;
196
207 return 0;
208 NEXT_PTR_LIST(one_rel);
209 NEXT_PTR_LIST(two_rel);
210 }
211 FINISH_PTR_LIST(two_rel);
212 FINISH_PTR_LIST(one_rel);
213
214 return 1;
215 }
216
217 int estates_equiv(struct smatch_state *one, struct smatch_state *two)
218 {
219 if (!one || !two)
220 return 0;
221 if (one == two)
222 return 1;
223 if (!rlists_equiv(estate_related(one), estate_related(two)))
224 return 0;
225 if (estate_capped(one) != estate_capped(two))
226 return 0;
227 if (estate_treat_untagged(one) != estate_treat_untagged(two))
228 return 0;
229 if (strcmp(one->name, two->name) == 0)
230 return 1;
231 return 0;
232 }
233
234 int estate_is_whole(struct smatch_state *state)
235 {
236 return is_whole_rl(estate_rl(state));
237 }
238
239 int estate_is_empty(struct smatch_state *state)
240 {
241 return state && !estate_rl(state);
242 }
243
244 int estate_is_unknown(struct smatch_state *state)
245 {
246 if (!estate_is_whole(state))
247 return 0;
248 if (estate_related(state))
249 return 0;
250 if (estate_has_fuzzy_max(state))
251 return 0;
252 return 1;
253 }
254
255 int estate_get_single_value(struct smatch_state *state, sval_t *sval)
256 {
257 sval_t min, max;
258
259 if (!estate_rl(state))
260 return 0;
261 min = rl_min(estate_rl(state));
262 max = rl_max(estate_rl(state));
263 if (sval_cmp(min, max) != 0)
264 return 0;
265 *sval = min;
266 return 1;
267 }
268
269 static struct data_info *alloc_dinfo(void)
270 {
271 struct data_info *ret;
272
273 ret = __alloc_data_info(0);
274 memset(ret, 0, sizeof(*ret));
275 return ret;
276 }
277
278 static struct data_info *alloc_dinfo_range(sval_t min, sval_t max)
279 {
280 struct data_info *ret;
|