2 * Copyright (C) 2009 Dan Carpenter.
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
20 #include "smatch_extra.h"
21 #include "smatch_slist.h"
23 ALLOCATOR(data_info
, "smatch extra data");
24 ALLOCATOR(data_range
, "data range");
25 __DO_ALLOCATOR(struct data_range
, sizeof(struct data_range
), __alignof__(struct data_range
),
26 "permanent ranges", perm_data_range
);
28 char *show_rl(struct range_list
*list
)
30 struct data_range
*tmp
;
36 FOR_EACH_PTR(list
, tmp
) {
38 strncat(full
, ",", 254 - strlen(full
));
39 if (sval_cmp(tmp
->min
, tmp
->max
) == 0) {
40 strncat(full
, sval_to_str(tmp
->min
), 254 - strlen(full
));
43 strncat(full
, sval_to_str(tmp
->min
), 254 - strlen(full
));
44 strncat(full
, "-", 254 - strlen(full
));
45 strncat(full
, sval_to_str(tmp
->max
), 254 - strlen(full
));
46 } END_FOR_EACH_PTR(tmp
);
47 return alloc_sname(full
);
50 static int sval_too_big(struct symbol
*type
, sval_t sval
)
52 if (type_bits(type
) == 64)
54 if (sval
.uvalue
> ((1ULL << type_bits(type
)) - 1))
59 static void add_range_t(struct symbol
*type
, struct range_list
**rl
, sval_t min
, sval_t max
)
61 /* If we're just adding a number, cast it and add it */
62 if (sval_cmp(min
, max
) == 0) {
63 add_range(rl
, sval_cast(type
, min
), sval_cast(type
, max
));
67 /* If the range is within the type range then add it */
68 if (sval_fits(type
, min
) && sval_fits(type
, max
)) {
69 add_range(rl
, sval_cast(type
, min
), sval_cast(type
, max
));
74 * If the range we are adding has more bits than the range type then
75 * add the whole range type. Eg:
76 * 0x8000000000000000 - 0xf000000000000000 -> cast to int
77 * This isn't totally the right thing to do. We could be more granular.
79 if (sval_too_big(type
, min
) || sval_too_big(type
, max
)) {
80 add_range(rl
, sval_type_min(type
), sval_type_max(type
));
84 /* Cast negative values to high positive values */
85 if (sval_is_negative(min
) && type_unsigned(type
)) {
86 if (sval_is_positive(max
)) {
87 if (sval_too_high(type
, max
)) {
88 add_range(rl
, sval_type_min(type
), sval_type_max(type
));
91 add_range(rl
, sval_type_val(type
, 0), sval_cast(type
, max
));
92 max
= sval_type_max(type
);
94 max
= sval_cast(type
, max
);
96 min
= sval_cast(type
, min
);
97 add_range(rl
, min
, max
);
100 /* Cast high positive numbers to negative */
101 if (sval_unsigned(max
) && sval_is_negative(sval_cast(type
, max
))) {
102 if (!sval_is_negative(sval_cast(type
, min
))) {
103 add_range(rl
, sval_cast(type
, min
), sval_type_max(type
));
104 min
= sval_type_min(type
);
106 min
= sval_cast(type
, min
);
108 max
= sval_cast(type
, max
);
109 add_range(rl
, min
, max
);
112 add_range(rl
, sval_cast(type
, min
), sval_cast(type
, max
));
116 static int str_to_comparison_arg_helper(const char *str
,
117 struct expression
*call
, int *comparison
,
118 struct expression
**arg
, char **endp
)
121 char *c
= (char *)str
;
130 *comparison
= SPECIAL_LTE
;
135 } else if (*c
== '=') {
138 *comparison
= SPECIAL_EQUAL
;
139 } else if (*c
== '>') {
142 *comparison
= SPECIAL_GTE
;
147 } else if (*c
== '!') {
150 *comparison
= SPECIAL_NOTEQUAL
;
159 param
= strtoll(c
, &c
, 10);
160 c
++; /* skip the ']' character */
166 *arg
= get_argument_from_call_expr(call
->args
, param
);
172 int str_to_comparison_arg(const char *str
, struct expression
*call
, int *comparison
, struct expression
**arg
)
181 return str_to_comparison_arg_helper(str
, call
, comparison
, arg
, NULL
);
184 static int get_val_from_key(int use_max
, struct symbol
*type
, char *c
, struct expression
*call
, char **endp
, sval_t
*sval
)
186 struct expression
*arg
;
191 ret
= sval_type_max(type
);
193 ret
= sval_type_min(type
);
195 if (!str_to_comparison_arg_helper(c
, call
, &comparison
, &arg
, endp
)) {
200 if (use_max
&& get_implied_max(arg
, &tmp
)) {
202 if (comparison
== '<') {
204 ret
= sval_binop(ret
, '-', tmp
);
207 if (!use_max
&& get_implied_min(arg
, &tmp
)) {
209 if (comparison
== '>') {
211 ret
= sval_binop(ret
, '+', tmp
);
219 static sval_t
add_one(sval_t sval
)
225 static sval_t
sub_one(sval_t sval
)
231 void filter_by_comparison(struct range_list
**rl
, int comparison
, struct range_list
*right
)
233 struct range_list
*left_orig
= *rl
;
234 struct range_list
*right_orig
= right
;
235 struct range_list
*ret_rl
= *rl
;
236 struct symbol
*cast_type
;
239 cast_type
= rl_type(left_orig
);
240 if (sval_type_max(rl_type(left_orig
)).uvalue
< sval_type_max(rl_type(right_orig
)).uvalue
)
241 cast_type
= rl_type(right_orig
);
242 if (sval_type_max(cast_type
).uvalue
< INT_MAX
)
243 cast_type
= &int_ctype
;
245 min
= sval_type_min(cast_type
);
246 max
= sval_type_max(cast_type
);
247 left_orig
= cast_rl(cast_type
, left_orig
);
248 right_orig
= cast_rl(cast_type
, right_orig
);
250 switch (comparison
) {
252 case SPECIAL_UNSIGNED_LT
:
253 ret_rl
= remove_range(left_orig
, rl_max(right_orig
), max
);
256 case SPECIAL_UNSIGNED_LTE
:
257 if (!sval_is_max(rl_max(right_orig
)))
258 ret_rl
= remove_range(left_orig
, add_one(rl_max(right_orig
)), max
);
261 if (!sval_is_max(rl_max(right_orig
)))
262 ret_rl
= remove_range(ret_rl
, add_one(rl_max(right_orig
)), max
);
263 if (!sval_is_min(rl_min(right_orig
)))
264 ret_rl
= remove_range(ret_rl
, min
, sub_one(rl_min(right_orig
)));
267 case SPECIAL_UNSIGNED_GTE
:
268 if (!sval_is_min(rl_min(right_orig
)))
269 ret_rl
= remove_range(left_orig
, min
, sub_one(rl_min(right_orig
)));
272 case SPECIAL_UNSIGNED_GT
:
273 ret_rl
= remove_range(left_orig
, min
, rl_min(right_orig
));
275 case SPECIAL_NOTEQUAL
:
276 if (sval_cmp(rl_min(right_orig
), rl_max(right_orig
)) == 0)
277 ret_rl
= remove_range(left_orig
, rl_min(right_orig
), rl_min(right_orig
));
280 sm_msg("internal error: unhandled comparison %s", show_special(comparison
));
284 *rl
= cast_rl(rl_type(*rl
), ret_rl
);
287 static struct range_list
*filter_by_comparison_call(char *c
, struct expression
*call
, char **endp
, struct range_list
*start_rl
)
289 struct expression
*arg
;
290 struct range_list
*right_orig
;
293 if (!str_to_comparison_arg_helper(c
, call
, &comparison
, &arg
, endp
))
296 if (!get_implied_rl(arg
, &right_orig
))
299 if (rl_type(start_rl
) == &int_ctype
&&
300 sval_is_negative(rl_min(start_rl
)) &&
301 type_unsigned(rl_type(right_orig
)))
302 right_orig
= cast_rl(&int_ctype
, right_orig
);
304 filter_by_comparison(&start_rl
, comparison
, right_orig
);
308 static sval_t
parse_val(int use_max
, struct expression
*call
, struct symbol
*type
, char *c
, char **endp
)
313 if (!strncmp(start
, "max", 3)) {
314 ret
= sval_type_max(type
);
316 } else if (!strncmp(start
, "u64max", 6)) {
317 ret
= sval_type_val(type
, ULLONG_MAX
);
319 } else if (!strncmp(start
, "s64max", 6)) {
320 ret
= sval_type_val(type
, LLONG_MAX
);
322 } else if (!strncmp(start
, "u32max", 6)) {
323 ret
= sval_type_val(type
, UINT_MAX
);
325 } else if (!strncmp(start
, "s32max", 6)) {
326 ret
= sval_type_val(type
, INT_MAX
);
328 } else if (!strncmp(start
, "u16max", 6)) {
329 ret
= sval_type_val(type
, USHRT_MAX
);
331 } else if (!strncmp(start
, "s16max", 6)) {
332 ret
= sval_type_val(type
, SHRT_MAX
);
334 } else if (!strncmp(start
, "min", 3)) {
335 ret
= sval_type_min(type
);
337 } else if (!strncmp(start
, "s64min", 6)) {
338 ret
= sval_type_val(type
, LLONG_MIN
);
340 } else if (!strncmp(start
, "s32min", 6)) {
341 ret
= sval_type_val(type
, INT_MIN
);
343 } else if (!strncmp(start
, "s16min", 6)) {
344 ret
= sval_type_val(type
, SHRT_MIN
);
346 } else if (!strncmp(start
, "long_min", 8)) {
347 ret
= sval_type_val(type
, LONG_MIN
);
349 } else if (!strncmp(start
, "long_max", 8)) {
350 ret
= sval_type_val(type
, LONG_MAX
);
352 } else if (!strncmp(start
, "ulong_max", 9)) {
353 ret
= sval_type_val(type
, ULONG_MAX
);
355 } else if (!strncmp(start
, "ptr_max", 7)) {
356 ret
= sval_type_val(type
, valid_ptr_max
);
358 } else if (start
[0] == '[') {
359 /* this parses [==p0] comparisons */
360 get_val_from_key(1, type
, start
, call
, &c
, &ret
);
361 } else if (type_positive_bits(type
) == 64) {
362 ret
= sval_type_val(type
, strtoull(start
, &c
, 10));
364 ret
= sval_type_val(type
, strtoll(start
, &c
, 10));
370 static char *jump_to_call_math(char *value
)
374 while (*c
&& *c
!= '[')
380 if (*c
== '<' || *c
== '=' || *c
== '>' || *c
== '!')
386 static void str_to_rl_helper(struct expression
*call
, struct symbol
*type
, char *str
, char **endp
, struct range_list
**rl
)
388 struct range_list
*rl_tmp
= NULL
;
392 min
= sval_type_min(type
);
393 max
= sval_type_max(type
);
395 while (*c
!= '\0' && *c
!= '[') {
398 min
= parse_val(0, call
, type
, c
, &c
);
402 if (*c
== '\0' || *c
== '[') {
403 add_range_t(type
, &rl_tmp
, min
, min
);
407 add_range_t(type
, &rl_tmp
, min
, min
);
412 sm_msg("debug XXX: trouble parsing %s c = %s", str
, c
);
418 max
= parse_val(1, call
, type
, c
, &c
);
419 add_range_t(type
, &rl_tmp
, min
, max
);
430 static void str_to_dinfo(struct expression
*call
, struct symbol
*type
, char *value
, struct data_info
*dinfo
)
432 struct range_list
*math_rl
;
435 struct range_list
*rl
= NULL
;
440 if (strcmp(value
, "empty") == 0)
443 if (strncmp(value
, "[==$", 4) == 0) {
444 struct expression
*arg
;
447 if (!str_to_comparison_arg(value
, call
, &comparison
, &arg
))
449 if (!get_implied_rl(arg
, &rl
))
454 str_to_rl_helper(call
, type
, value
, &c
, &rl
);
458 call_math
= jump_to_call_math(value
);
459 if (call_math
&& parse_call_math_rl(call
, call_math
, &math_rl
)) {
460 rl
= rl_intersection(rl
, math_rl
);
465 * For now if we already tried to handle the call math and couldn't
466 * figure it out then bail.
468 if (jump_to_call_math(c
) == c
+ 1)
471 rl
= filter_by_comparison_call(c
, call
, &c
, rl
);
474 rl
= cast_rl(type
, rl
);
475 dinfo
->value_ranges
= rl
;
478 void str_to_rl(struct symbol
*type
, char *value
, struct range_list
**rl
)
480 struct data_info dinfo
= {};
482 str_to_dinfo(NULL
, type
, value
, &dinfo
);
483 *rl
= dinfo
.value_ranges
;
486 void call_results_to_rl(struct expression
*expr
, struct symbol
*type
, char *value
, struct range_list
**rl
)
488 struct data_info dinfo
= {};
490 str_to_dinfo(strip_expr(expr
), type
, value
, &dinfo
);
491 *rl
= dinfo
.value_ranges
;
494 int is_whole_rl(struct range_list
*rl
)
496 struct data_range
*drange
;
498 if (ptr_list_empty(rl
))
500 drange
= first_ptr_list((struct ptr_list
*)rl
);
501 if (sval_is_min(drange
->min
) && sval_is_max(drange
->max
))
506 int is_whole_rl_non_zero(struct range_list
*rl
)
508 struct data_range
*drange
;
510 if (ptr_list_empty(rl
))
512 drange
= first_ptr_list((struct ptr_list
*)rl
);
513 if (sval_unsigned(drange
->min
) &&
514 drange
->min
.value
== 1 &&
515 sval_is_max(drange
->max
))
517 if (!sval_is_min(drange
->min
) || drange
->max
.value
!= -1)
519 drange
= last_ptr_list((struct ptr_list
*)rl
);
520 if (drange
->min
.value
!= 1 || !sval_is_max(drange
->max
))
525 sval_t
rl_min(struct range_list
*rl
)
527 struct data_range
*drange
;
530 ret
.type
= &llong_ctype
;
531 ret
.value
= LLONG_MIN
;
532 if (ptr_list_empty(rl
))
534 drange
= first_ptr_list((struct ptr_list
*)rl
);
538 sval_t
rl_max(struct range_list
*rl
)
540 struct data_range
*drange
;
543 ret
.type
= &llong_ctype
;
544 ret
.value
= LLONG_MAX
;
545 if (ptr_list_empty(rl
))
547 drange
= last_ptr_list((struct ptr_list
*)rl
);
551 int rl_to_sval(struct range_list
*rl
, sval_t
*sval
)
560 if (sval_cmp(min
, max
) != 0)
566 struct symbol
*rl_type(struct range_list
*rl
)
570 return rl_min(rl
).type
;
573 static struct data_range
*alloc_range_helper_sval(sval_t min
, sval_t max
, int perm
)
575 struct data_range
*ret
;
578 ret
= __alloc_perm_data_range(0);
580 ret
= __alloc_data_range(0);
586 struct data_range
*alloc_range(sval_t min
, sval_t max
)
588 return alloc_range_helper_sval(min
, max
, 0);
591 struct data_range
*alloc_range_perm(sval_t min
, sval_t max
)
593 return alloc_range_helper_sval(min
, max
, 1);
596 struct range_list
*alloc_rl(sval_t min
, sval_t max
)
598 struct range_list
*rl
= NULL
;
600 if (sval_cmp(min
, max
) > 0)
601 return alloc_whole_rl(min
.type
);
603 add_range(&rl
, min
, max
);
607 struct range_list
*alloc_whole_rl(struct symbol
*type
)
609 if (!type
|| type_positive_bits(type
) < 0)
611 if (type
->type
== SYM_ARRAY
)
614 return alloc_rl(sval_type_min(type
), sval_type_max(type
));
617 void add_range(struct range_list
**list
, sval_t min
, sval_t max
)
619 struct data_range
*tmp
;
620 struct data_range
*new = NULL
;
623 if (sval_cmp(min
, max
) > 0) {
624 min
= sval_type_min(min
.type
);
625 max
= sval_type_max(min
.type
);
629 * FIXME: This has a problem merging a range_list like: min-0,3-max
630 * with a range like 1-2. You end up with min-2,3-max instead of
633 FOR_EACH_PTR(*list
, tmp
) {
635 /* Sometimes we overlap with more than one range
636 so we have to delete or modify the next range. */
637 if (!sval_is_max(max
) && max
.value
+ 1 == tmp
->min
.value
) {
638 /* join 2 ranges here */
640 DELETE_CURRENT_PTR(tmp
);
644 /* Doesn't overlap with the next one. */
645 if (sval_cmp(max
, tmp
->min
) < 0)
648 if (sval_cmp(max
, tmp
->max
) <= 0) {
649 /* Partially overlaps the next one. */
651 DELETE_CURRENT_PTR(tmp
);
654 /* Completely overlaps the next one. */
655 DELETE_CURRENT_PTR(tmp
);
656 /* there could be more ranges to delete */
660 if (!sval_is_max(max
) && max
.value
+ 1 == tmp
->min
.value
) {
661 /* join 2 ranges into a big range */
662 new = alloc_range(min
, tmp
->max
);
663 REPLACE_CURRENT_PTR(tmp
, new);
666 if (sval_cmp(max
, tmp
->min
) < 0) { /* new range entirely below */
667 new = alloc_range(min
, max
);
668 INSERT_CURRENT(new, tmp
);
671 if (sval_cmp(min
, tmp
->min
) < 0) { /* new range partially below */
672 if (sval_cmp(max
, tmp
->max
) < 0)
676 new = alloc_range(min
, max
);
677 REPLACE_CURRENT_PTR(tmp
, new);
682 if (sval_cmp(max
, tmp
->max
) <= 0) /* new range already included */
684 if (sval_cmp(min
, tmp
->max
) <= 0) { /* new range partially above */
686 new = alloc_range(min
, max
);
687 REPLACE_CURRENT_PTR(tmp
, new);
691 if (!sval_is_min(min
) && min
.value
- 1 == tmp
->max
.value
) {
692 /* join 2 ranges into a big range */
693 new = alloc_range(tmp
->min
, max
);
694 REPLACE_CURRENT_PTR(tmp
, new);
698 /* the new range is entirely above the existing ranges */
699 } END_FOR_EACH_PTR(tmp
);
702 new = alloc_range(min
, max
);
703 add_ptr_list(list
, new);
706 struct range_list
*clone_rl(struct range_list
*list
)
708 struct data_range
*tmp
;
709 struct range_list
*ret
= NULL
;
711 FOR_EACH_PTR(list
, tmp
) {
712 add_ptr_list(&ret
, tmp
);
713 } END_FOR_EACH_PTR(tmp
);
717 struct range_list
*clone_rl_permanent(struct range_list
*list
)
719 struct data_range
*tmp
;
720 struct data_range
*new;
721 struct range_list
*ret
= NULL
;
723 FOR_EACH_PTR(list
, tmp
) {
724 new = alloc_range_perm(tmp
->min
, tmp
->max
);
725 add_ptr_list(&ret
, new);
726 } END_FOR_EACH_PTR(tmp
);
730 struct range_list
*rl_union(struct range_list
*one
, struct range_list
*two
)
732 struct data_range
*tmp
;
733 struct range_list
*ret
= NULL
;
735 FOR_EACH_PTR(one
, tmp
) {
736 add_range(&ret
, tmp
->min
, tmp
->max
);
737 } END_FOR_EACH_PTR(tmp
);
738 FOR_EACH_PTR(two
, tmp
) {
739 add_range(&ret
, tmp
->min
, tmp
->max
);
740 } END_FOR_EACH_PTR(tmp
);
744 struct range_list
*remove_range(struct range_list
*list
, sval_t min
, sval_t max
)
746 struct data_range
*tmp
;
747 struct range_list
*ret
= NULL
;
752 min
= sval_cast(rl_type(list
), min
);
753 max
= sval_cast(rl_type(list
), max
);
754 if (sval_cmp(min
, max
) > 0) {
760 FOR_EACH_PTR(list
, tmp
) {
761 if (sval_cmp(tmp
->max
, min
) < 0) {
762 add_range(&ret
, tmp
->min
, tmp
->max
);
765 if (sval_cmp(tmp
->min
, max
) > 0) {
766 add_range(&ret
, tmp
->min
, tmp
->max
);
769 if (sval_cmp(tmp
->min
, min
) >= 0 && sval_cmp(tmp
->max
, max
) <= 0)
771 if (sval_cmp(tmp
->min
, min
) >= 0) {
773 add_range(&ret
, max
, tmp
->max
);
774 } else if (sval_cmp(tmp
->max
, max
) <= 0) {
776 add_range(&ret
, tmp
->min
, min
);
780 add_range(&ret
, tmp
->min
, min
);
781 add_range(&ret
, max
, tmp
->max
);
783 } END_FOR_EACH_PTR(tmp
);
787 int ranges_equiv(struct data_range
*one
, struct data_range
*two
)
793 if (sval_cmp(one
->min
, two
->min
) != 0)
795 if (sval_cmp(one
->max
, two
->max
) != 0)
800 int rl_equiv(struct range_list
*one
, struct range_list
*two
)
802 struct data_range
*one_range
;
803 struct data_range
*two_range
;
808 PREPARE_PTR_LIST(one
, one_range
);
809 PREPARE_PTR_LIST(two
, two_range
);
811 if (!one_range
&& !two_range
)
813 if (!ranges_equiv(one_range
, two_range
))
815 NEXT_PTR_LIST(one_range
);
816 NEXT_PTR_LIST(two_range
);
818 FINISH_PTR_LIST(two_range
);
819 FINISH_PTR_LIST(one_range
);
824 int true_comparison_range(struct data_range
*left
, int comparison
, struct data_range
*right
)
826 switch (comparison
) {
828 case SPECIAL_UNSIGNED_LT
:
829 if (sval_cmp(left
->min
, right
->max
) < 0)
832 case SPECIAL_UNSIGNED_LTE
:
834 if (sval_cmp(left
->min
, right
->max
) <= 0)
838 if (sval_cmp(left
->max
, right
->min
) < 0)
840 if (sval_cmp(left
->min
, right
->max
) > 0)
843 case SPECIAL_UNSIGNED_GTE
:
845 if (sval_cmp(left
->max
, right
->min
) >= 0)
849 case SPECIAL_UNSIGNED_GT
:
850 if (sval_cmp(left
->max
, right
->min
) > 0)
853 case SPECIAL_NOTEQUAL
:
854 if (sval_cmp(left
->min
, left
->max
) != 0)
856 if (sval_cmp(right
->min
, right
->max
) != 0)
858 if (sval_cmp(left
->min
, right
->min
) != 0)
862 sm_msg("unhandled comparison %d\n", comparison
);
868 int true_comparison_range_LR(int comparison
, struct data_range
*var
, struct data_range
*val
, int left
)
871 return true_comparison_range(var
, comparison
, val
);
873 return true_comparison_range(val
, comparison
, var
);
876 static int false_comparison_range_sval(struct data_range
*left
, int comparison
, struct data_range
*right
)
878 switch (comparison
) {
880 case SPECIAL_UNSIGNED_LT
:
881 if (sval_cmp(left
->max
, right
->min
) >= 0)
884 case SPECIAL_UNSIGNED_LTE
:
886 if (sval_cmp(left
->max
, right
->min
) > 0)
890 if (sval_cmp(left
->min
, left
->max
) != 0)
892 if (sval_cmp(right
->min
, right
->max
) != 0)
894 if (sval_cmp(left
->min
, right
->min
) != 0)
897 case SPECIAL_UNSIGNED_GTE
:
899 if (sval_cmp(left
->min
, right
->max
) < 0)
903 case SPECIAL_UNSIGNED_GT
:
904 if (sval_cmp(left
->min
, right
->max
) <= 0)
907 case SPECIAL_NOTEQUAL
:
908 if (sval_cmp(left
->max
, right
->min
) < 0)
910 if (sval_cmp(left
->min
, right
->max
) > 0)
914 sm_msg("unhandled comparison %d\n", comparison
);
920 int false_comparison_range_LR(int comparison
, struct data_range
*var
, struct data_range
*val
, int left
)
923 return false_comparison_range_sval(var
, comparison
, val
);
925 return false_comparison_range_sval(val
, comparison
, var
);
928 int possibly_true(struct expression
*left
, int comparison
, struct expression
*right
)
930 struct range_list
*rl_left
, *rl_right
;
931 struct data_range
*tmp_left
, *tmp_right
;
934 if (!get_implied_rl(left
, &rl_left
))
936 if (!get_implied_rl(right
, &rl_right
))
939 type
= rl_type(rl_left
);
940 if (type_positive_bits(type
) < type_positive_bits(rl_type(rl_right
)))
941 type
= rl_type(rl_right
);
942 if (type_positive_bits(type
) < 31)
945 rl_left
= cast_rl(type
, rl_left
);
946 rl_right
= cast_rl(type
, rl_right
);
948 FOR_EACH_PTR(rl_left
, tmp_left
) {
949 FOR_EACH_PTR(rl_right
, tmp_right
) {
950 if (true_comparison_range(tmp_left
, comparison
, tmp_right
))
952 } END_FOR_EACH_PTR(tmp_right
);
953 } END_FOR_EACH_PTR(tmp_left
);
957 int possibly_false(struct expression
*left
, int comparison
, struct expression
*right
)
959 struct range_list
*rl_left
, *rl_right
;
960 struct data_range
*tmp_left
, *tmp_right
;
963 if (!get_implied_rl(left
, &rl_left
))
965 if (!get_implied_rl(right
, &rl_right
))
968 type
= rl_type(rl_left
);
969 if (type_positive_bits(type
) < type_positive_bits(rl_type(rl_right
)))
970 type
= rl_type(rl_right
);
971 if (type_positive_bits(type
) < 31)
974 rl_left
= cast_rl(type
, rl_left
);
975 rl_right
= cast_rl(type
, rl_right
);
977 FOR_EACH_PTR(rl_left
, tmp_left
) {
978 FOR_EACH_PTR(rl_right
, tmp_right
) {
979 if (false_comparison_range_sval(tmp_left
, comparison
, tmp_right
))
981 } END_FOR_EACH_PTR(tmp_right
);
982 } END_FOR_EACH_PTR(tmp_left
);
986 int possibly_true_rl(struct range_list
*left_ranges
, int comparison
, struct range_list
*right_ranges
)
988 struct data_range
*left_tmp
, *right_tmp
;
991 if (!left_ranges
|| !right_ranges
)
994 type
= rl_type(left_ranges
);
995 if (type_positive_bits(type
) < type_positive_bits(rl_type(right_ranges
)))
996 type
= rl_type(right_ranges
);
997 if (type_positive_bits(type
) < 31)
1000 left_ranges
= cast_rl(type
, left_ranges
);
1001 right_ranges
= cast_rl(type
, right_ranges
);
1003 FOR_EACH_PTR(left_ranges
, left_tmp
) {
1004 FOR_EACH_PTR(right_ranges
, right_tmp
) {
1005 if (true_comparison_range(left_tmp
, comparison
, right_tmp
))
1007 } END_FOR_EACH_PTR(right_tmp
);
1008 } END_FOR_EACH_PTR(left_tmp
);
1012 int possibly_false_rl(struct range_list
*left_ranges
, int comparison
, struct range_list
*right_ranges
)
1014 struct data_range
*left_tmp
, *right_tmp
;
1015 struct symbol
*type
;
1017 if (!left_ranges
|| !right_ranges
)
1020 type
= rl_type(left_ranges
);
1021 if (type_positive_bits(type
) < type_positive_bits(rl_type(right_ranges
)))
1022 type
= rl_type(right_ranges
);
1023 if (type_positive_bits(type
) < 31)
1026 left_ranges
= cast_rl(type
, left_ranges
);
1027 right_ranges
= cast_rl(type
, right_ranges
);
1029 FOR_EACH_PTR(left_ranges
, left_tmp
) {
1030 FOR_EACH_PTR(right_ranges
, right_tmp
) {
1031 if (false_comparison_range_sval(left_tmp
, comparison
, right_tmp
))
1033 } END_FOR_EACH_PTR(right_tmp
);
1034 } END_FOR_EACH_PTR(left_tmp
);
1038 /* FIXME: the _rl here stands for right left so really it should be _lr */
1039 int possibly_true_rl_LR(int comparison
, struct range_list
*a
, struct range_list
*b
, int left
)
1042 return possibly_true_rl(a
, comparison
, b
);
1044 return possibly_true_rl(b
, comparison
, a
);
1047 int possibly_false_rl_LR(int comparison
, struct range_list
*a
, struct range_list
*b
, int left
)
1050 return possibly_false_rl(a
, comparison
, b
);
1052 return possibly_false_rl(b
, comparison
, a
);
1055 int rl_has_sval(struct range_list
*rl
, sval_t sval
)
1057 struct data_range
*tmp
;
1059 FOR_EACH_PTR(rl
, tmp
) {
1060 if (sval_cmp(tmp
->min
, sval
) <= 0 &&
1061 sval_cmp(tmp
->max
, sval
) >= 0)
1063 } END_FOR_EACH_PTR(tmp
);
1067 void tack_on(struct range_list
**list
, struct data_range
*drange
)
1069 add_ptr_list(list
, drange
);
1072 void push_rl(struct range_list_stack
**rl_stack
, struct range_list
*rl
)
1074 add_ptr_list(rl_stack
, rl
);
1077 struct range_list
*pop_rl(struct range_list_stack
**rl_stack
)
1079 struct range_list
*rl
;
1081 rl
= last_ptr_list((struct ptr_list
*)*rl_stack
);
1082 delete_ptr_list_last((struct ptr_list
**)rl_stack
);
1086 struct range_list
*top_rl(struct range_list_stack
*rl_stack
)
1088 struct range_list
*rl
;
1090 rl
= last_ptr_list((struct ptr_list
*)rl_stack
);
1094 void filter_top_rl(struct range_list_stack
**rl_stack
, struct range_list
*filter
)
1096 struct range_list
*rl
;
1098 rl
= pop_rl(rl_stack
);
1099 rl
= rl_filter(rl
, filter
);
1100 push_rl(rl_stack
, rl
);
1103 struct range_list
*rl_truncate_cast(struct symbol
*type
, struct range_list
*rl
)
1105 struct data_range
*tmp
;
1106 struct range_list
*ret
= NULL
;
1112 if (!type
|| type
== rl_type(rl
))
1115 FOR_EACH_PTR(rl
, tmp
) {
1118 if (type_bits(type
) < type_bits(rl_type(rl
))) {
1119 min
.uvalue
= tmp
->min
.uvalue
& ((1ULL << type_bits(type
)) - 1);
1120 max
.uvalue
= tmp
->max
.uvalue
& ((1ULL << type_bits(type
)) - 1);
1122 if (sval_cmp(min
, max
) > 0) {
1123 min
= sval_cast(type
, min
);
1124 max
= sval_cast(type
, max
);
1126 add_range_t(type
, &ret
, min
, max
);
1127 } END_FOR_EACH_PTR(tmp
);
1132 static int rl_is_sane(struct range_list
*rl
)
1134 struct data_range
*tmp
;
1135 struct symbol
*type
;
1138 FOR_EACH_PTR(rl
, tmp
) {
1139 if (!sval_fits(type
, tmp
->min
))
1141 if (!sval_fits(type
, tmp
->max
))
1143 if (sval_cmp(tmp
->min
, tmp
->max
) > 0)
1145 } END_FOR_EACH_PTR(tmp
);
1150 static int rl_type_consistent(struct range_list
*rl
)
1152 struct data_range
*tmp
;
1153 struct symbol
*type
;
1156 FOR_EACH_PTR(rl
, tmp
) {
1157 if (type
!= tmp
->min
.type
|| type
!= tmp
->max
.type
)
1159 } END_FOR_EACH_PTR(tmp
);
1163 static struct range_list
*cast_to_bool(struct range_list
*rl
)
1165 struct data_range
*tmp
;
1166 struct range_list
*ret
= NULL
;
1169 sval_t min
= { .type
= &bool_ctype
};
1170 sval_t max
= { .type
= &bool_ctype
};
1172 FOR_EACH_PTR(rl
, tmp
) {
1173 if (tmp
->min
.value
|| tmp
->max
.value
)
1175 if (sval_is_negative(tmp
->min
) &&
1176 sval_is_negative(tmp
->max
))
1178 if (tmp
->min
.value
== 0 ||
1179 tmp
->max
.value
== 0)
1181 if (sval_is_negative(tmp
->min
) &&
1184 } END_FOR_EACH_PTR(tmp
);
1191 add_range(&ret
, min
, max
);
1195 struct range_list
*cast_rl(struct symbol
*type
, struct range_list
*rl
)
1197 struct data_range
*tmp
;
1198 struct range_list
*ret
= NULL
;
1205 if (!rl_is_sane(rl
))
1206 return alloc_whole_rl(type
);
1207 if (type
== rl_type(rl
) && rl_type_consistent(rl
))
1210 if (type
== &bool_ctype
)
1211 return cast_to_bool(rl
);
1213 FOR_EACH_PTR(rl
, tmp
) {
1214 add_range_t(type
, &ret
, tmp
->min
, tmp
->max
);
1215 } END_FOR_EACH_PTR(tmp
);
1218 return alloc_whole_rl(type
);
1223 struct range_list
*rl_invert(struct range_list
*orig
)
1225 struct range_list
*ret
= NULL
;
1226 struct data_range
*tmp
;
1227 sval_t gap_min
, abs_max
, sval
;
1231 if (type_bits(rl_type(orig
)) < 0) /* void type mostly */
1234 gap_min
= sval_type_min(rl_min(orig
).type
);
1235 abs_max
= sval_type_max(rl_max(orig
).type
);
1237 FOR_EACH_PTR(orig
, tmp
) {
1238 if (sval_cmp(tmp
->min
, gap_min
) > 0) {
1239 sval
= sval_type_val(tmp
->min
.type
, tmp
->min
.value
- 1);
1240 add_range(&ret
, gap_min
, sval
);
1242 if (sval_cmp(tmp
->max
, abs_max
) == 0)
1244 gap_min
= sval_type_val(tmp
->max
.type
, tmp
->max
.value
+ 1);
1245 } END_FOR_EACH_PTR(tmp
);
1247 if (sval_cmp(gap_min
, abs_max
) <= 0)
1248 add_range(&ret
, gap_min
, abs_max
);
1253 struct range_list
*rl_filter(struct range_list
*rl
, struct range_list
*filter
)
1255 struct data_range
*tmp
;
1257 FOR_EACH_PTR(filter
, tmp
) {
1258 rl
= remove_range(rl
, tmp
->min
, tmp
->max
);
1259 } END_FOR_EACH_PTR(tmp
);
1264 struct range_list
*rl_intersection(struct range_list
*one
, struct range_list
*two
)
1266 struct range_list
*one_orig
;
1267 struct range_list
*two_orig
;
1268 struct range_list
*ret
;
1269 struct symbol
*ret_type
;
1270 struct symbol
*small_type
;
1271 struct symbol
*large_type
;
1281 ret_type
= rl_type(one
);
1282 small_type
= rl_type(one
);
1283 large_type
= rl_type(two
);
1285 if (type_bits(rl_type(two
)) < type_bits(small_type
)) {
1286 small_type
= rl_type(two
);
1287 large_type
= rl_type(one
);
1290 one
= cast_rl(large_type
, one
);
1291 two
= cast_rl(large_type
, two
);
1294 one
= rl_invert(one
);
1295 two
= rl_invert(two
);
1297 ret
= rl_filter(ret
, one
);
1298 ret
= rl_filter(ret
, two
);
1300 one
= cast_rl(small_type
, one_orig
);
1301 two
= cast_rl(small_type
, two_orig
);
1303 one
= rl_invert(one
);
1304 two
= rl_invert(two
);
1306 ret
= cast_rl(small_type
, ret
);
1307 ret
= rl_filter(ret
, one
);
1308 ret
= rl_filter(ret
, two
);
1310 return cast_rl(ret_type
, ret
);
1313 static struct range_list
*handle_mod_rl(struct range_list
*left
, struct range_list
*right
)
1318 max
= rl_max(right
);
1319 if (sval_is_max(max
))
1324 if (sval_is_negative(max
))
1326 if (sval_cmp(rl_max(left
), max
) < 0)
1330 return alloc_rl(zero
, max
);
1333 static struct range_list
*get_neg_rl(struct range_list
*rl
)
1335 struct data_range
*tmp
;
1336 struct data_range
*new;
1337 struct range_list
*ret
= NULL
;
1341 if (sval_is_positive(rl_min(rl
)))
1344 FOR_EACH_PTR(rl
, tmp
) {
1345 if (sval_is_positive(tmp
->min
))
1347 if (sval_is_positive(tmp
->max
)) {
1348 new = alloc_range(tmp
->min
, tmp
->max
);
1349 new->max
.value
= -1;
1350 add_range(&ret
, new->min
, new->max
);
1353 add_range(&ret
, tmp
->min
, tmp
->max
);
1354 } END_FOR_EACH_PTR(tmp
);
1359 static struct range_list
*get_pos_rl(struct range_list
*rl
)
1361 struct data_range
*tmp
;
1362 struct data_range
*new;
1363 struct range_list
*ret
= NULL
;
1367 if (sval_is_negative(rl_max(rl
)))
1370 FOR_EACH_PTR(rl
, tmp
) {
1371 if (sval_is_negative(tmp
->max
))
1373 if (sval_is_positive(tmp
->min
)) {
1374 add_range(&ret
, tmp
->min
, tmp
->max
);
1377 new = alloc_range(tmp
->min
, tmp
->max
);
1379 add_range(&ret
, new->min
, new->max
);
1380 } END_FOR_EACH_PTR(tmp
);
1385 static struct range_list
*divide_rl_helper(struct range_list
*left
, struct range_list
*right
)
1387 sval_t right_min
, right_max
;
1390 if (!left
|| !right
)
1393 /* let's assume we never divide by zero */
1394 right_min
= rl_min(right
);
1395 right_max
= rl_max(right
);
1396 if (right_min
.value
== 0 && right_max
.value
== 0)
1398 if (right_min
.value
== 0)
1399 right_min
.value
= 1;
1400 if (right_max
.value
== 0)
1401 right_max
.value
= -1;
1403 max
= sval_binop(rl_max(left
), '/', right_min
);
1404 min
= sval_binop(rl_min(left
), '/', right_max
);
1406 return alloc_rl(min
, max
);
1409 static struct range_list
*handle_divide_rl(struct range_list
*left
, struct range_list
*right
)
1411 struct range_list
*left_neg
, *left_pos
, *right_neg
, *right_pos
;
1412 struct range_list
*neg_neg
, *neg_pos
, *pos_neg
, *pos_pos
;
1413 struct range_list
*ret
;
1415 if (is_whole_rl(right
))
1418 left_neg
= get_neg_rl(left
);
1419 left_pos
= get_pos_rl(left
);
1420 right_neg
= get_neg_rl(right
);
1421 right_pos
= get_pos_rl(right
);
1423 neg_neg
= divide_rl_helper(left_neg
, right_neg
);
1424 neg_pos
= divide_rl_helper(left_neg
, right_pos
);
1425 pos_neg
= divide_rl_helper(left_pos
, right_neg
);
1426 pos_pos
= divide_rl_helper(left_pos
, right_pos
);
1428 ret
= rl_union(neg_neg
, neg_pos
);
1429 ret
= rl_union(ret
, pos_neg
);
1430 return rl_union(ret
, pos_pos
);
1433 static struct range_list
*handle_add_mult_rl(struct range_list
*left
, int op
, struct range_list
*right
)
1437 if (sval_binop_overflows(rl_min(left
), op
, rl_min(right
)))
1439 min
= sval_binop(rl_min(left
), op
, rl_min(right
));
1441 if (sval_binop_overflows(rl_max(left
), op
, rl_max(right
)))
1443 max
= sval_binop(rl_max(left
), op
, rl_max(right
));
1445 return alloc_rl(min
, max
);
1448 static unsigned long long rl_bits_always_set(struct range_list
*rl
)
1450 return sval_fls_mask(rl_min(rl
));
1453 static unsigned long long rl_bits_maybe_set(struct range_list
*rl
)
1455 return sval_fls_mask(rl_max(rl
));
1458 static struct range_list
*handle_OR_rl(struct range_list
*left
, struct range_list
*right
)
1460 unsigned long long left_min
, left_max
, right_min
, right_max
;
1464 if ((rl_to_sval(left
, &sval
) || rl_to_sval(right
, &sval
)) &&
1465 !sval_binop_overflows(rl_max(left
), '+', rl_max(right
)))
1466 return rl_binop(left
, '+', right
);
1468 left_min
= rl_bits_always_set(left
);
1469 left_max
= rl_bits_maybe_set(left
);
1470 right_min
= rl_bits_always_set(right
);
1471 right_max
= rl_bits_maybe_set(right
);
1473 min
.type
= max
.type
= &ullong_ctype
;
1474 min
.uvalue
= left_min
| right_min
;
1475 max
.uvalue
= left_max
| right_max
;
1477 return cast_rl(rl_type(left
), alloc_rl(min
, max
));
1480 static struct range_list
*handle_XOR_rl(struct range_list
*left
, struct range_list
*right
)
1482 unsigned long long left_set
, left_maybe
;
1483 unsigned long long right_set
, right_maybe
;
1486 left_set
= rl_bits_always_set(left
);
1487 left_maybe
= rl_bits_maybe_set(left
);
1489 right_set
= rl_bits_always_set(right
);
1490 right_maybe
= rl_bits_maybe_set(right
);
1492 zero
= max
= rl_min(left
);
1494 max
.uvalue
= fls_mask((left_maybe
| right_maybe
) ^ (left_set
& right_set
));
1496 return cast_rl(rl_type(left
), alloc_rl(zero
, max
));
1499 struct range_list
*rl_binop(struct range_list
*left
, int op
, struct range_list
*right
)
1501 struct symbol
*cast_type
;
1502 sval_t left_sval
, right_sval
;
1503 struct range_list
*ret
= NULL
;
1505 cast_type
= rl_type(left
);
1506 if (sval_type_max(rl_type(left
)).uvalue
< sval_type_max(rl_type(right
)).uvalue
)
1507 cast_type
= rl_type(right
);
1508 if (sval_type_max(cast_type
).uvalue
< INT_MAX
)
1509 cast_type
= &int_ctype
;
1511 left
= cast_rl(cast_type
, left
);
1512 right
= cast_rl(cast_type
, right
);
1514 if (!left
|| !right
)
1515 return alloc_whole_rl(cast_type
);
1517 if (rl_to_sval(left
, &left_sval
) && rl_to_sval(right
, &right_sval
)) {
1518 sval_t val
= sval_binop(left_sval
, op
, right_sval
);
1519 return alloc_rl(val
, val
);
1524 ret
= handle_mod_rl(left
, right
);
1527 ret
= handle_divide_rl(left
, right
);
1531 ret
= handle_add_mult_rl(left
, op
, right
);
1534 ret
= handle_OR_rl(left
, right
);
1537 ret
= handle_XOR_rl(left
, right
);
1540 /* FIXME: Do the rest as well */
1543 case SPECIAL_RIGHTSHIFT
:
1544 case SPECIAL_LEFTSHIFT
:
1549 ret
= alloc_whole_rl(cast_type
);
1553 void free_rl(struct range_list
**rlist
)
1555 __free_ptr_list((struct ptr_list
**)rlist
);
1558 static void free_single_dinfo(struct data_info
*dinfo
)
1560 free_rl(&dinfo
->value_ranges
);
1563 static void free_dinfos(struct allocation_blob
*blob
)
1565 unsigned int size
= sizeof(struct data_info
);
1566 unsigned int offset
= 0;
1568 while (offset
< blob
->offset
) {
1569 free_single_dinfo((struct data_info
*)(blob
->data
+ offset
));
1574 void free_data_info_allocs(void)
1576 struct allocator_struct
*desc
= &data_info_allocator
;
1577 struct allocation_blob
*blob
= desc
->blobs
;
1580 desc
->allocations
= 0;
1581 desc
->total_bytes
= 0;
1582 desc
->useful_bytes
= 0;
1583 desc
->freelist
= NULL
;
1585 struct allocation_blob
*next
= blob
->next
;
1587 blob_free(blob
, desc
->chunking
);
1590 clear_data_range_alloc();
1593 void split_comparison_rl(struct range_list
*left_orig
, int op
, struct range_list
*right_orig
,
1594 struct range_list
**left_true_rl
, struct range_list
**left_false_rl
,
1595 struct range_list
**right_true_rl
, struct range_list
**right_false_rl
)
1597 struct range_list
*left_true
, *left_false
;
1598 struct range_list
*right_true
, *right_false
;
1601 min
= sval_type_min(rl_type(left_orig
));
1602 max
= sval_type_max(rl_type(left_orig
));
1604 left_true
= clone_rl(left_orig
);
1605 left_false
= clone_rl(left_orig
);
1606 right_true
= clone_rl(right_orig
);
1607 right_false
= clone_rl(right_orig
);
1611 case SPECIAL_UNSIGNED_LT
:
1612 left_true
= remove_range(left_orig
, rl_max(right_orig
), max
);
1613 if (!sval_is_min(rl_min(right_orig
))) {
1614 left_false
= remove_range(left_orig
, min
, sub_one(rl_min(right_orig
)));
1617 right_true
= remove_range(right_orig
, min
, rl_min(left_orig
));
1618 if (!sval_is_max(rl_max(left_orig
)))
1619 right_false
= remove_range(right_orig
, add_one(rl_max(left_orig
)), max
);
1621 case SPECIAL_UNSIGNED_LTE
:
1623 if (!sval_is_max(rl_max(right_orig
)))
1624 left_true
= remove_range(left_orig
, add_one(rl_max(right_orig
)), max
);
1625 left_false
= remove_range(left_orig
, min
, rl_min(right_orig
));
1627 if (!sval_is_min(rl_min(left_orig
)))
1628 right_true
= remove_range(right_orig
, min
, sub_one(rl_min(left_orig
)));
1629 right_false
= remove_range(right_orig
, rl_max(left_orig
), max
);
1631 if (sval_cmp(rl_min(left_orig
), rl_min(right_orig
)) == 0)
1632 left_false
= remove_range(left_false
, rl_min(left_orig
), rl_min(left_orig
));
1633 if (sval_cmp(rl_max(left_orig
), rl_max(right_orig
)) == 0)
1634 right_false
= remove_range(right_false
, rl_max(left_orig
), rl_max(left_orig
));
1637 if (!sval_is_max(rl_max(right_orig
))) {
1638 left_true
= remove_range(left_true
, add_one(rl_max(right_orig
)), max
);
1640 if (!sval_is_min(rl_min(right_orig
))) {
1641 left_true
= remove_range(left_true
, min
, sub_one(rl_min(right_orig
)));
1643 if (sval_cmp(rl_min(right_orig
), rl_max(right_orig
)) == 0)
1644 left_false
= remove_range(left_orig
, rl_min(right_orig
), rl_min(right_orig
));
1646 if (!sval_is_max(rl_max(left_orig
)))
1647 right_true
= remove_range(right_true
, add_one(rl_max(left_orig
)), max
);
1648 if (!sval_is_min(rl_min(left_orig
)))
1649 right_true
= remove_range(right_true
, min
, sub_one(rl_min(left_orig
)));
1650 if (sval_cmp(rl_min(left_orig
), rl_max(left_orig
)) == 0)
1651 right_false
= remove_range(right_orig
, rl_min(left_orig
), rl_min(left_orig
));
1653 case SPECIAL_UNSIGNED_GTE
:
1655 if (!sval_is_min(rl_min(right_orig
)))
1656 left_true
= remove_range(left_orig
, min
, sub_one(rl_min(right_orig
)));
1657 left_false
= remove_range(left_orig
, rl_max(right_orig
), max
);
1659 if (!sval_is_max(rl_max(left_orig
)))
1660 right_true
= remove_range(right_orig
, add_one(rl_max(left_orig
)), max
);
1661 right_false
= remove_range(right_orig
, min
, rl_min(left_orig
));
1663 if (sval_cmp(rl_min(left_orig
), rl_min(right_orig
)) == 0)
1664 right_false
= remove_range(right_false
, rl_min(left_orig
), rl_min(left_orig
));
1665 if (sval_cmp(rl_max(left_orig
), rl_max(right_orig
)) == 0)
1666 left_false
= remove_range(left_false
, rl_max(left_orig
), rl_max(left_orig
));
1669 case SPECIAL_UNSIGNED_GT
:
1670 left_true
= remove_range(left_orig
, min
, rl_min(right_orig
));
1671 if (!sval_is_max(rl_max(right_orig
)))
1672 left_false
= remove_range(left_orig
, add_one(rl_max(right_orig
)), max
);
1674 right_true
= remove_range(right_orig
, rl_max(left_orig
), max
);
1675 if (!sval_is_min(rl_min(left_orig
)))
1676 right_false
= remove_range(right_orig
, min
, sub_one(rl_min(left_orig
)));
1678 case SPECIAL_NOTEQUAL
:
1679 if (!sval_is_max(rl_max(right_orig
)))
1680 left_false
= remove_range(left_false
, add_one(rl_max(right_orig
)), max
);
1681 if (!sval_is_min(rl_min(right_orig
)))
1682 left_false
= remove_range(left_false
, min
, sub_one(rl_min(right_orig
)));
1683 if (sval_cmp(rl_min(right_orig
), rl_max(right_orig
)) == 0)
1684 left_true
= remove_range(left_orig
, rl_min(right_orig
), rl_min(right_orig
));
1686 if (!sval_is_max(rl_max(left_orig
)))
1687 right_false
= remove_range(right_false
, add_one(rl_max(left_orig
)), max
);
1688 if (!sval_is_min(rl_min(left_orig
)))
1689 right_false
= remove_range(right_false
, min
, sub_one(rl_min(left_orig
)));
1690 if (sval_cmp(rl_min(left_orig
), rl_max(left_orig
)) == 0)
1691 right_true
= remove_range(right_orig
, rl_min(left_orig
), rl_min(left_orig
));
1694 sm_msg("internal error: unhandled comparison %d", op
);
1699 *left_true_rl
= left_true
;
1700 *left_false_rl
= left_false
;
1702 if (right_true_rl
) {
1703 *right_true_rl
= right_true
;
1704 *right_false_rl
= right_false
;