4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
12 #include "smatch_slist.h"
13 #include "smatch_extra.h"
15 static struct range_list
*_get_rl(struct expression
*expr
, int implied
);
16 static struct range_list
*handle_variable(struct expression
*expr
, int implied
);
18 static sval_t zero
= {.type
= &int_ctype
, {.value
= 0} };
19 static sval_t one
= {.type
= &int_ctype
, {.value
= 1} };
21 static struct range_list
*rl_zero(void)
23 return alloc_rl(zero
, zero
);
26 static struct range_list
*rl_one(void)
28 return alloc_rl(one
, one
);
39 static struct range_list
*last_stmt_rl(struct statement
*stmt
, int implied
)
44 stmt
= last_ptr_list((struct ptr_list
*)stmt
->stmts
);
45 if (stmt
->type
!= STMT_EXPRESSION
)
47 return _get_rl(stmt
->expression
, implied
);
50 static struct range_list
*handle_expression_statement_rl(struct expression
*expr
, int implied
)
52 return last_stmt_rl(get_expression_statement(expr
), implied
);
55 static struct range_list
*handle_ampersand_rl(int implied
)
57 if (implied
== RL_EXACT
|| implied
== RL_HARD
)
59 return alloc_rl(valid_ptr_min_sval
, valid_ptr_max_sval
);
62 static struct range_list
*handle_negate_rl(struct expression
*expr
, int implied
)
64 if (known_condition_true(expr
->unop
))
66 if (known_condition_false(expr
->unop
))
69 if (implied
== RL_EXACT
)
72 if (implied_condition_true(expr
->unop
))
74 if (implied_condition_false(expr
->unop
))
76 return alloc_rl(zero
, one
);
79 static struct range_list
*handle_bitwise_negate(struct expression
*expr
, int implied
)
81 struct range_list
*rl
;
84 rl
= _get_rl(expr
->unop
, implied
);
85 if (!rl_to_sval(rl
, &sval
))
87 sval
= sval_preop(sval
, '~');
88 sval_cast(get_type(expr
->unop
), sval
);
89 return alloc_rl(sval
, sval
);
92 static struct range_list
*handle_minus_preop(struct expression
*expr
, int implied
)
94 struct range_list
*rl
;
97 rl
= _get_rl(expr
->unop
, implied
);
98 if (!rl_to_sval(rl
, &sval
))
100 sval
= sval_preop(sval
, '-');
101 return alloc_rl(sval
, sval
);
104 static struct range_list
*handle_preop_rl(struct expression
*expr
, int implied
)
108 return handle_ampersand_rl(implied
);
110 return handle_negate_rl(expr
, implied
);
112 return handle_bitwise_negate(expr
, implied
);
114 return handle_minus_preop(expr
, implied
);
116 return handle_variable(expr
, implied
);
118 return handle_expression_statement_rl(expr
, implied
);
124 static struct range_list
*handle_divide_rl(struct expression
*expr
, int implied
)
126 struct range_list
*left_rl
, *right_rl
;
130 type
= get_type(expr
);
132 left_rl
= _get_rl(expr
->left
, implied
);
133 left_rl
= cast_rl(type
, left_rl
);
134 right_rl
= _get_rl(expr
->right
, implied
);
135 right_rl
= cast_rl(type
, right_rl
);
137 if (!left_rl
|| !right_rl
)
139 if (is_whole_rl(left_rl
) || is_whole_rl(right_rl
))
141 if (sval_is_negative(rl_min(left_rl
)) || sval_cmp_val(rl_min(right_rl
), 0) <= 0)
144 max
= rl_max(left_rl
);
145 if (!sval_is_max(max
))
146 max
= sval_binop(max
, '/', rl_min(right_rl
));
147 min
= sval_binop(rl_min(left_rl
), '/', rl_max(right_rl
));
148 return alloc_rl(min
, max
);
151 static struct range_list
*handle_subtract_rl(struct expression
*expr
, int implied
)
154 struct range_list
*left_rl
, *right_rl
;
155 sval_t max
, min
, tmp
;
158 type
= get_type(expr
);
159 comparison
= get_comparison(expr
->left
, expr
->right
);
161 left_rl
= _get_rl(expr
->left
, implied
);
162 left_rl
= cast_rl(type
, left_rl
);
163 right_rl
= _get_rl(expr
->right
, implied
);
164 right_rl
= cast_rl(type
, right_rl
);
166 if ((!left_rl
|| !right_rl
) &&
167 (implied
== RL_EXACT
|| implied
== RL_HARD
|| implied
== RL_FUZZY
))
171 left_rl
= alloc_whole_rl(type
);
173 right_rl
= alloc_whole_rl(type
);
175 /* negative values complicate everything fix this later */
176 if (sval_is_negative(rl_min(right_rl
)))
178 max
= rl_max(left_rl
);
180 switch (comparison
) {
182 case SPECIAL_UNSIGNED_GT
:
183 min
= sval_type_val(type
, 1);
184 max
= rl_max(left_rl
);
187 case SPECIAL_UNSIGNED_GTE
:
188 min
= sval_type_val(type
, 0);
189 max
= rl_max(left_rl
);
192 if (sval_binop_overflows(rl_min(left_rl
), '-', rl_max(right_rl
)))
194 min
= sval_type_min(type
);
197 if (!sval_binop_overflows(rl_min(left_rl
), '-', rl_max(right_rl
))) {
198 tmp
= sval_binop(rl_min(left_rl
), '-', rl_max(right_rl
));
199 if (sval_cmp(tmp
, min
) > 0)
203 if (!sval_is_max(rl_max(left_rl
))) {
204 tmp
= sval_binop(rl_max(left_rl
), '-', rl_min(right_rl
));
205 if (sval_cmp(tmp
, max
) < 0)
209 if (sval_is_min(min
) && sval_is_max(max
))
212 return cast_rl(type
, alloc_rl(min
, max
));
215 static struct range_list
*handle_mod_rl(struct expression
*expr
, int implied
)
217 struct range_list
*rl
;
218 sval_t left
, right
, sval
;
220 if (implied
== RL_EXACT
) {
221 if (!get_value(expr
->right
, &right
))
223 if (!get_value(expr
->left
, &left
))
225 sval
= sval_binop(left
, '%', right
);
226 return alloc_rl(sval
, sval
);
228 /* if we can't figure out the right side it's probably hopeless */
229 if (!get_implied_value(expr
->right
, &right
))
232 right
= sval_cast(get_type(expr
), right
);
235 rl
= _get_rl(expr
->left
, implied
);
236 if (rl
&& rl_max(rl
).uvalue
< right
.uvalue
)
237 right
.uvalue
= rl_max(rl
).uvalue
;
239 return alloc_rl(zero
, right
);
242 static sval_t
sval_lowest_set_bit(sval_t sval
)
247 for (i
= 0; i
< 64; i
++) {
248 if (sval
.uvalue
& 1ULL << i
) {
251 sval
.uvalue
&= ~(1ULL << i
);
257 static struct range_list
*handle_bitwise_AND(struct expression
*expr
, int implied
)
260 struct range_list
*left_rl
, *right_rl
;
263 if (implied
!= RL_IMPLIED
&& implied
!= RL_ABSOLUTE
)
266 type
= get_type(expr
);
268 if (get_implied_value(expr
->left
, &known
)) {
271 min
= sval_lowest_set_bit(known
);
272 left_rl
= alloc_rl(min
, known
);
273 left_rl
= cast_rl(type
, left_rl
);
274 add_range(&left_rl
, sval_type_val(type
, 0), sval_type_val(type
, 0));
276 left_rl
= _get_rl(expr
->left
, implied
);
278 left_rl
= cast_rl(type
, left_rl
);
279 left_rl
= alloc_rl(sval_type_val(type
, 0), rl_max(left_rl
));
281 if (implied
== RL_HARD
)
283 left_rl
= alloc_whole_rl(type
);
287 if (get_implied_value(expr
->right
, &known
)) {
290 min
= sval_lowest_set_bit(known
);
291 right_rl
= alloc_rl(min
, known
);
292 right_rl
= cast_rl(type
, right_rl
);
293 add_range(&right_rl
, sval_type_val(type
, 0), sval_type_val(type
, 0));
295 right_rl
= _get_rl(expr
->right
, implied
);
297 right_rl
= cast_rl(type
, right_rl
);
298 right_rl
= alloc_rl(sval_type_val(type
, 0), rl_max(right_rl
));
300 if (implied
== RL_HARD
)
302 right_rl
= alloc_whole_rl(type
);
306 return rl_intersection(left_rl
, right_rl
);
309 static struct range_list
*handle_bitwise_OR(struct expression
*expr
, int implied
)
312 struct range_list
*left_rl
, *right_rl
;
314 if (implied
!= RL_IMPLIED
&& implied
!= RL_ABSOLUTE
)
317 type
= get_type(expr
);
319 get_absolute_rl(expr
->left
, &left_rl
);
320 get_absolute_rl(expr
->right
, &right_rl
);
321 left_rl
= cast_rl(type
, left_rl
);
322 right_rl
= cast_rl(type
, right_rl
);
324 return rl_union(left_rl
, right_rl
);
327 static struct range_list
*handle_right_shift(struct expression
*expr
, int implied
)
329 struct range_list
*left_rl
;
333 if (implied
== RL_EXACT
|| implied
== RL_HARD
)
335 /* this is hopeless without the right side */
336 if (!get_implied_value(expr
->right
, &right
))
338 left_rl
= _get_rl(expr
->left
, implied
);
340 max
= rl_max(left_rl
);
341 min
= rl_min(left_rl
);
343 if (implied
== RL_FUZZY
)
345 max
= sval_type_max(get_type(expr
->left
));
346 min
= sval_type_val(get_type(expr
->left
), 0);
349 max
= sval_binop(max
, SPECIAL_RIGHTSHIFT
, right
);
350 min
= sval_binop(min
, SPECIAL_RIGHTSHIFT
, right
);
351 return alloc_rl(min
, max
);
354 static struct range_list
*handle_left_shift(struct expression
*expr
, int implied
)
356 struct range_list
*left_rl
, *res
;
361 if (implied
== RL_EXACT
|| implied
== RL_HARD
)
363 /* this is hopeless without the right side */
364 if (!get_implied_value(expr
->right
, &right
))
366 left_rl
= _get_rl(expr
->left
, implied
);
368 max
= rl_max(left_rl
);
369 min
= rl_min(left_rl
);
370 if (min
.value
== 0) {
375 if (implied
== RL_FUZZY
)
377 max
= sval_type_max(get_type(expr
->left
));
378 min
= sval_type_val(get_type(expr
->left
), 1);
382 max
= sval_binop(max
, SPECIAL_LEFTSHIFT
, right
);
383 min
= sval_binop(min
, SPECIAL_LEFTSHIFT
, right
);
384 res
= alloc_rl(min
, max
);
386 res
= rl_union(res
, rl_zero());
390 static struct range_list
*handle_known_binop(struct expression
*expr
)
394 if (!get_value(expr
->left
, &left
))
396 if (!get_value(expr
->right
, &right
))
398 left
= sval_binop(left
, expr
->op
, right
);
399 return alloc_rl(left
, left
);
402 static struct range_list
*handle_binop_rl(struct expression
*expr
, int implied
)
405 struct range_list
*left_rl
, *right_rl
, *rl
;
408 rl
= handle_known_binop(expr
);
411 if (implied
== RL_EXACT
)
416 return handle_mod_rl(expr
, implied
);
418 return handle_bitwise_AND(expr
, implied
);
420 return handle_bitwise_OR(expr
, implied
);
421 case SPECIAL_RIGHTSHIFT
:
422 return handle_right_shift(expr
, implied
);
423 case SPECIAL_LEFTSHIFT
:
424 return handle_left_shift(expr
, implied
);
426 return handle_subtract_rl(expr
, implied
);
428 return handle_divide_rl(expr
, implied
);
431 type
= get_type(expr
);
432 left_rl
= _get_rl(expr
->left
, implied
);
433 left_rl
= cast_rl(type
, left_rl
);
434 right_rl
= _get_rl(expr
->right
, implied
);
435 right_rl
= cast_rl(type
, right_rl
);
437 if (!left_rl
|| !right_rl
)
440 if (sval_binop_overflows(rl_min(left_rl
), expr
->op
, rl_min(right_rl
)))
442 min
= sval_binop(rl_min(left_rl
), expr
->op
, rl_min(right_rl
));
444 if (sval_binop_overflows(rl_max(left_rl
), expr
->op
, rl_max(right_rl
))) {
450 max
= sval_type_max(get_type(expr
));
453 max
= sval_binop(rl_max(left_rl
), expr
->op
, rl_max(right_rl
));
456 return alloc_rl(min
, max
);
459 static int do_comparison(struct expression
*expr
)
461 struct range_list
*left_ranges
= NULL
;
462 struct range_list
*right_ranges
= NULL
;
463 int poss_true
, poss_false
;
466 type
= get_type(expr
);
468 get_implied_rl(expr
->left
, &left_ranges
);
469 get_implied_rl(expr
->right
, &right_ranges
);
470 left_ranges
= cast_rl(type
, left_ranges
);
471 right_ranges
= cast_rl(type
, right_ranges
);
473 poss_true
= possibly_true_rl(left_ranges
, expr
->op
, right_ranges
);
474 poss_false
= possibly_false_rl(left_ranges
, expr
->op
, right_ranges
);
476 free_rl(&left_ranges
);
477 free_rl(&right_ranges
);
479 if (!poss_true
&& !poss_false
)
481 if (poss_true
&& !poss_false
)
483 if (!poss_true
&& poss_false
)
488 static struct range_list
*handle_comparison_rl(struct expression
*expr
, int implied
)
493 if (get_value(expr
->left
, &left
) && get_value(expr
->right
, &right
)) {
494 struct data_range tmp_left
, tmp_right
;
498 tmp_right
.min
= right
;
499 tmp_right
.max
= right
;
500 if (true_comparison_range(&tmp_left
, expr
->op
, &tmp_right
))
505 if (implied
== RL_EXACT
)
508 res
= do_comparison(expr
);
514 return alloc_rl(zero
, one
);
517 static struct range_list
*handle_logical_rl(struct expression
*expr
, int implied
)
523 if (implied
== RL_EXACT
) {
524 if (get_value(expr
->left
, &left
))
526 if (get_value(expr
->right
, &right
))
529 if (get_implied_value(expr
->left
, &left
))
531 if (get_implied_value(expr
->right
, &right
))
536 case SPECIAL_LOGICAL_OR
:
537 if (left_known
&& left
.value
)
539 if (right_known
&& right
.value
)
541 if (left_known
&& right_known
)
544 case SPECIAL_LOGICAL_AND
:
545 if (left_known
&& right_known
) {
546 if (left
.value
&& right
.value
)
555 if (implied
== RL_EXACT
)
558 return alloc_rl(zero
, one
);
561 static struct range_list
*handle_conditional_rl(struct expression
*expr
, int implied
)
563 struct range_list
*true_rl
, *false_rl
;
565 int final_pass_orig
= final_pass
;
567 if (known_condition_true(expr
->conditional
))
568 return _get_rl(expr
->cond_true
, implied
);
569 if (known_condition_false(expr
->conditional
))
570 return _get_rl(expr
->cond_false
, implied
);
572 if (implied
== RL_EXACT
)
575 if (implied_condition_true(expr
->conditional
))
576 return _get_rl(expr
->cond_true
, implied
);
577 if (implied_condition_false(expr
->conditional
))
578 return _get_rl(expr
->cond_false
, implied
);
581 /* this becomes a problem with deeply nested conditional statements */
585 type
= get_type(expr
);
587 __push_fake_cur_slist();
589 __split_whole_condition(expr
->conditional
);
590 true_rl
= _get_rl(expr
->cond_true
, implied
);
591 __push_true_states();
592 __use_false_states();
593 false_rl
= _get_rl(expr
->cond_false
, implied
);
594 __merge_true_states();
595 __free_fake_cur_slist();
596 final_pass
= final_pass_orig
;
598 if (!true_rl
|| !false_rl
)
600 true_rl
= cast_rl(type
, true_rl
);
601 false_rl
= cast_rl(type
, false_rl
);
603 return rl_union(true_rl
, false_rl
);
606 static int get_fuzzy_max_helper(struct expression
*expr
, sval_t
*max
)
608 struct smatch_state
*state
;
611 if (get_hard_max(expr
, &sval
)) {
616 state
= get_state_expr(SMATCH_EXTRA
, expr
);
617 if (!state
|| !estate_has_fuzzy_max(state
))
619 *max
= sval_cast(get_type(expr
), estate_get_fuzzy_max(state
));
623 static int get_fuzzy_min_helper(struct expression
*expr
, sval_t
*min
)
626 struct sm_state
*tmp
;
629 sm
= get_sm_state_expr(SMATCH_EXTRA
, expr
);
633 if (!sval_is_min(estate_min(sm
->state
))) {
634 *min
= estate_min(sm
->state
);
638 sval
= sval_type_max(estate_type(sm
->state
));
639 FOR_EACH_PTR(sm
->possible
, tmp
) {
642 new_max
= estate_max(tmp
->state
);
643 if (sval_cmp(new_max
, sval
) < 0)
645 } END_FOR_EACH_PTR(tmp
);
647 if (sval_is_max(sval
))
649 *min
= sval_cast(get_type(expr
), sval
);
653 int get_const_value(struct expression
*expr
, sval_t
*sval
)
658 if (expr
->type
!= EXPR_SYMBOL
|| !expr
->symbol
)
661 if (!(sym
->ctype
.modifiers
& MOD_CONST
))
663 if (get_value(sym
->initializer
, &right
)) {
664 *sval
= sval_cast(get_type(expr
), right
);
670 static struct range_list
*handle_variable(struct expression
*expr
, int implied
)
672 struct smatch_state
*state
;
673 struct range_list
*rl
;
674 sval_t sval
, min
, max
;
676 if (get_const_value(expr
, &sval
))
677 return alloc_rl(sval
, sval
);
685 state
= get_state_expr(SMATCH_EXTRA
, expr
);
686 if (!state
|| !state
->data
) {
687 if (implied
== RL_HARD
)
689 if (get_local_rl(expr
, &rl
))
691 if (get_db_type_rl(expr
, &rl
))
695 if (implied
== RL_HARD
&& !estate_has_hard_max(state
))
697 return clone_rl(estate_rl(state
));
699 if (!get_fuzzy_min_helper(expr
, &min
))
700 min
= sval_type_min(get_type(expr
));
701 if (!get_fuzzy_max_helper(expr
, &max
))
703 /* fuzzy ranges are often inverted */
704 if (sval_cmp(min
, max
) > 0) {
709 return alloc_rl(min
, max
);
714 static sval_t
handle_sizeof(struct expression
*expr
)
719 ret
= sval_blank(expr
);
720 sym
= expr
->cast_type
;
722 sym
= evaluate_expression(expr
->cast_expression
);
724 * Expressions of restricted types will possibly get
725 * promoted - check that here
727 if (is_restricted_type(sym
)) {
728 if (sym
->bit_size
< bits_in_int
)
730 } else if (is_fouled_type(sym
)) {
734 examine_symbol_type(sym
);
736 ret
.type
= size_t_ctype
;
737 if (sym
->bit_size
<= 0) /* sizeof(void) */ {
738 if (get_real_base_type(sym
) == &void_ctype
)
743 ret
.value
= bits_to_bytes(sym
->bit_size
);
748 static struct range_list
*handle_call_rl(struct expression
*expr
, int implied
)
750 struct range_list
*rl
;
752 if (implied
== RL_EXACT
|| implied
== RL_HARD
|| implied
== RL_FUZZY
)
755 if (get_implied_return(expr
, &rl
))
757 return db_return_vals(expr
);
760 static struct range_list
*handle_cast(struct expression
*expr
, int implied
)
762 struct range_list
*rl
;
765 type
= get_type(expr
);
766 rl
= _get_rl(expr
->cast_expression
, implied
);
768 return cast_rl(type
, rl
);
769 if (implied
== RL_ABSOLUTE
)
770 return alloc_whole_rl(type
);
771 if (implied
== RL_IMPLIED
&& type
&&
772 type
->bit_size
> 0 && type
->bit_size
< 32)
773 return alloc_whole_rl(type
);
777 static struct range_list
*_get_rl(struct expression
*expr
, int implied
)
779 struct range_list
*rl
;
783 expr
= strip_parens(expr
);
786 type
= get_type(expr
);
788 switch (expr
->type
) {
790 sval
= sval_from_val(expr
, expr
->value
);
791 rl
= alloc_rl(sval
, sval
);
794 rl
= handle_preop_rl(expr
, implied
);
797 rl
= _get_rl(expr
->unop
, implied
);
800 case EXPR_FORCE_CAST
:
801 case EXPR_IMPLIED_CAST
:
802 rl
= handle_cast(expr
, implied
);
805 rl
= handle_binop_rl(expr
, implied
);
808 rl
= handle_comparison_rl(expr
, implied
);
811 rl
= handle_logical_rl(expr
, implied
);
815 sval
= handle_sizeof(expr
);
816 rl
= alloc_rl(sval
, sval
);
819 case EXPR_CONDITIONAL
:
820 rl
= handle_conditional_rl(expr
, implied
);
823 rl
= handle_call_rl(expr
, implied
);
826 rl
= handle_variable(expr
, implied
);
831 if (type
&& implied
== RL_ABSOLUTE
)
832 return alloc_whole_rl(type
);
836 /* returns 1 if it can get a value literal or else returns 0 */
837 int get_value(struct expression
*expr
, sval_t
*sval
)
839 struct range_list
*rl
;
841 rl
= _get_rl(expr
, RL_EXACT
);
842 if (!rl_to_sval(rl
, sval
))
847 int get_implied_value(struct expression
*expr
, sval_t
*sval
)
849 struct range_list
*rl
;
851 rl
= _get_rl(expr
, RL_IMPLIED
);
852 if (!rl_to_sval(rl
, sval
))
857 int get_implied_min(struct expression
*expr
, sval_t
*sval
)
859 struct range_list
*rl
;
861 rl
= _get_rl(expr
, RL_IMPLIED
);
868 int get_implied_max(struct expression
*expr
, sval_t
*sval
)
870 struct range_list
*rl
;
872 rl
= _get_rl(expr
, RL_IMPLIED
);
879 int get_implied_rl(struct expression
*expr
, struct range_list
**rl
)
881 *rl
= _get_rl(expr
, RL_IMPLIED
);
887 int get_absolute_rl(struct expression
*expr
, struct range_list
**rl
)
889 *rl
= _get_rl(expr
, RL_ABSOLUTE
);
891 *rl
= alloc_whole_rl(get_type(expr
));
895 int get_implied_rl_var_sym(const char *var
, struct symbol
*sym
, struct range_list
**rl
)
897 struct smatch_state
*state
;
899 state
= get_state(SMATCH_EXTRA
, var
, sym
);
900 *rl
= estate_rl(state
);
906 int get_hard_max(struct expression
*expr
, sval_t
*sval
)
908 struct range_list
*rl
;
910 rl
= _get_rl(expr
, RL_HARD
);
917 int get_fuzzy_min(struct expression
*expr
, sval_t
*sval
)
919 struct range_list
*rl
;
922 rl
= _get_rl(expr
, RL_FUZZY
);
926 if (sval_is_negative(tmp
) && sval_is_min(tmp
))
932 int get_fuzzy_max(struct expression
*expr
, sval_t
*sval
)
934 struct range_list
*rl
;
937 rl
= _get_rl(expr
, RL_FUZZY
);
941 if (max
.uvalue
> INT_MAX
- 10000)
947 int get_absolute_min(struct expression
*expr
, sval_t
*sval
)
949 struct range_list
*rl
;
952 type
= get_type(expr
);
954 type
= &llong_ctype
; // FIXME: this is wrong but places assume get type can't fail.
955 rl
= _get_rl(expr
, RL_ABSOLUTE
);
959 *sval
= sval_type_min(type
);
961 if (sval_cmp(*sval
, sval_type_min(type
)) < 0)
962 *sval
= sval_type_min(type
);
966 int get_absolute_max(struct expression
*expr
, sval_t
*sval
)
968 struct range_list
*rl
;
971 type
= get_type(expr
);
974 rl
= _get_rl(expr
, RL_ABSOLUTE
);
978 *sval
= sval_type_max(type
);
980 if (sval_cmp(sval_type_max(type
), *sval
) < 0)
981 *sval
= sval_type_max(type
);
985 int known_condition_true(struct expression
*expr
)
992 if (get_value(expr
, &tmp
) && tmp
.value
)
998 int known_condition_false(struct expression
*expr
)
1006 if (expr
->type
== EXPR_CALL
) {
1007 if (sym_name_is("__builtin_constant_p", expr
->fn
))
1013 int implied_condition_true(struct expression
*expr
)
1020 if (known_condition_true(expr
))
1022 if (get_implied_value(expr
, &tmp
) && tmp
.value
)
1025 if (expr
->type
== EXPR_POSTOP
)
1026 return implied_condition_true(expr
->unop
);
1028 if (expr
->type
== EXPR_PREOP
&& expr
->op
== SPECIAL_DECREMENT
)
1029 return implied_not_equal(expr
->unop
, 1);
1030 if (expr
->type
== EXPR_PREOP
&& expr
->op
== SPECIAL_INCREMENT
)
1031 return implied_not_equal(expr
->unop
, -1);
1033 expr
= strip_expr(expr
);
1034 switch (expr
->type
) {
1036 if (do_comparison(expr
) == 1)
1040 if (expr
->op
== '!') {
1041 if (implied_condition_false(expr
->unop
))
1047 if (implied_not_equal(expr
, 0) == 1)
1054 int implied_condition_false(struct expression
*expr
)
1056 struct expression
*tmp
;
1062 if (known_condition_false(expr
))
1065 switch (expr
->type
) {
1067 if (do_comparison(expr
) == 2)
1070 if (expr
->op
== '!') {
1071 if (implied_condition_true(expr
->unop
))
1075 tmp
= strip_expr(expr
);
1077 return implied_condition_false(tmp
);
1080 if (get_implied_value(expr
, &sval
) && sval
.value
== 0)