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
)
625 struct smatch_state
*state
;
628 state
= get_state_expr(SMATCH_EXTRA
, expr
);
629 if (!state
|| !estate_rl(state
))
632 sval
= estate_min(state
);
633 if (sval_is_negative(sval
) && sval_is_min(sval
))
636 if (sval_is_max(sval
))
639 *min
= sval_cast(get_type(expr
), sval
);
643 int get_const_value(struct expression
*expr
, sval_t
*sval
)
648 if (expr
->type
!= EXPR_SYMBOL
|| !expr
->symbol
)
651 if (!(sym
->ctype
.modifiers
& MOD_CONST
))
653 if (get_value(sym
->initializer
, &right
)) {
654 *sval
= sval_cast(get_type(expr
), right
);
660 static struct range_list
*handle_variable(struct expression
*expr
, int implied
)
662 struct smatch_state
*state
;
663 struct range_list
*rl
;
664 sval_t sval
, min
, max
;
666 if (get_const_value(expr
, &sval
))
667 return alloc_rl(sval
, sval
);
675 state
= get_state_expr(SMATCH_EXTRA
, expr
);
676 if (!state
|| !state
->data
) {
677 if (implied
== RL_HARD
)
679 if (get_local_rl(expr
, &rl
))
681 if (get_db_type_rl(expr
, &rl
))
685 if (implied
== RL_HARD
&& !estate_has_hard_max(state
))
687 return clone_rl(estate_rl(state
));
689 if (!get_fuzzy_min_helper(expr
, &min
))
690 min
= sval_type_min(get_type(expr
));
691 if (!get_fuzzy_max_helper(expr
, &max
))
693 /* fuzzy ranges are often inverted */
694 if (sval_cmp(min
, max
) > 0) {
699 return alloc_rl(min
, max
);
704 static sval_t
handle_sizeof(struct expression
*expr
)
709 ret
= sval_blank(expr
);
710 sym
= expr
->cast_type
;
712 sym
= evaluate_expression(expr
->cast_expression
);
714 * Expressions of restricted types will possibly get
715 * promoted - check that here
717 if (is_restricted_type(sym
)) {
718 if (sym
->bit_size
< bits_in_int
)
720 } else if (is_fouled_type(sym
)) {
724 examine_symbol_type(sym
);
726 ret
.type
= size_t_ctype
;
727 if (sym
->bit_size
<= 0) /* sizeof(void) */ {
728 if (get_real_base_type(sym
) == &void_ctype
)
733 ret
.value
= bits_to_bytes(sym
->bit_size
);
738 static struct range_list
*handle_call_rl(struct expression
*expr
, int implied
)
740 struct range_list
*rl
;
742 if (implied
== RL_EXACT
|| implied
== RL_HARD
|| implied
== RL_FUZZY
)
745 if (get_implied_return(expr
, &rl
))
747 return db_return_vals(expr
);
750 static struct range_list
*handle_cast(struct expression
*expr
, int implied
)
752 struct range_list
*rl
;
755 type
= get_type(expr
);
756 rl
= _get_rl(expr
->cast_expression
, implied
);
758 return cast_rl(type
, rl
);
759 if (implied
== RL_ABSOLUTE
)
760 return alloc_whole_rl(type
);
761 if (implied
== RL_IMPLIED
&& type
&&
762 type
->bit_size
> 0 && type
->bit_size
< 32)
763 return alloc_whole_rl(type
);
767 static struct range_list
*_get_rl(struct expression
*expr
, int implied
)
769 struct range_list
*rl
;
773 expr
= strip_parens(expr
);
776 type
= get_type(expr
);
778 switch (expr
->type
) {
780 sval
= sval_from_val(expr
, expr
->value
);
781 rl
= alloc_rl(sval
, sval
);
784 rl
= handle_preop_rl(expr
, implied
);
787 rl
= _get_rl(expr
->unop
, implied
);
790 case EXPR_FORCE_CAST
:
791 case EXPR_IMPLIED_CAST
:
792 rl
= handle_cast(expr
, implied
);
795 rl
= handle_binop_rl(expr
, implied
);
798 rl
= handle_comparison_rl(expr
, implied
);
801 rl
= handle_logical_rl(expr
, implied
);
805 sval
= handle_sizeof(expr
);
806 rl
= alloc_rl(sval
, sval
);
809 case EXPR_CONDITIONAL
:
810 rl
= handle_conditional_rl(expr
, implied
);
813 rl
= handle_call_rl(expr
, implied
);
816 rl
= handle_variable(expr
, implied
);
821 if (type
&& implied
== RL_ABSOLUTE
)
822 return alloc_whole_rl(type
);
826 /* returns 1 if it can get a value literal or else returns 0 */
827 int get_value(struct expression
*expr
, sval_t
*sval
)
829 struct range_list
*rl
;
831 rl
= _get_rl(expr
, RL_EXACT
);
832 if (!rl_to_sval(rl
, sval
))
837 int get_implied_value(struct expression
*expr
, sval_t
*sval
)
839 struct range_list
*rl
;
841 rl
= _get_rl(expr
, RL_IMPLIED
);
842 if (!rl_to_sval(rl
, sval
))
847 int get_implied_min(struct expression
*expr
, sval_t
*sval
)
849 struct range_list
*rl
;
851 rl
= _get_rl(expr
, RL_IMPLIED
);
858 int get_implied_max(struct expression
*expr
, sval_t
*sval
)
860 struct range_list
*rl
;
862 rl
= _get_rl(expr
, RL_IMPLIED
);
869 int get_implied_rl(struct expression
*expr
, struct range_list
**rl
)
871 *rl
= _get_rl(expr
, RL_IMPLIED
);
877 int get_absolute_rl(struct expression
*expr
, struct range_list
**rl
)
879 *rl
= _get_rl(expr
, RL_ABSOLUTE
);
881 *rl
= alloc_whole_rl(get_type(expr
));
885 int get_implied_rl_var_sym(const char *var
, struct symbol
*sym
, struct range_list
**rl
)
887 struct smatch_state
*state
;
889 state
= get_state(SMATCH_EXTRA
, var
, sym
);
890 *rl
= estate_rl(state
);
896 int get_hard_max(struct expression
*expr
, sval_t
*sval
)
898 struct range_list
*rl
;
900 rl
= _get_rl(expr
, RL_HARD
);
907 int get_fuzzy_min(struct expression
*expr
, sval_t
*sval
)
909 struct range_list
*rl
;
912 rl
= _get_rl(expr
, RL_FUZZY
);
916 if (sval_is_negative(tmp
) && sval_is_min(tmp
))
922 int get_fuzzy_max(struct expression
*expr
, sval_t
*sval
)
924 struct range_list
*rl
;
927 rl
= _get_rl(expr
, RL_FUZZY
);
931 if (max
.uvalue
> INT_MAX
- 10000)
937 int get_absolute_min(struct expression
*expr
, sval_t
*sval
)
939 struct range_list
*rl
;
942 type
= get_type(expr
);
944 type
= &llong_ctype
; // FIXME: this is wrong but places assume get type can't fail.
945 rl
= _get_rl(expr
, RL_ABSOLUTE
);
949 *sval
= sval_type_min(type
);
951 if (sval_cmp(*sval
, sval_type_min(type
)) < 0)
952 *sval
= sval_type_min(type
);
956 int get_absolute_max(struct expression
*expr
, sval_t
*sval
)
958 struct range_list
*rl
;
961 type
= get_type(expr
);
964 rl
= _get_rl(expr
, RL_ABSOLUTE
);
968 *sval
= sval_type_max(type
);
970 if (sval_cmp(sval_type_max(type
), *sval
) < 0)
971 *sval
= sval_type_max(type
);
975 int known_condition_true(struct expression
*expr
)
982 if (get_value(expr
, &tmp
) && tmp
.value
)
988 int known_condition_false(struct expression
*expr
)
996 if (expr
->type
== EXPR_CALL
) {
997 if (sym_name_is("__builtin_constant_p", expr
->fn
))
1003 int implied_condition_true(struct expression
*expr
)
1010 if (known_condition_true(expr
))
1012 if (get_implied_value(expr
, &tmp
) && tmp
.value
)
1015 if (expr
->type
== EXPR_POSTOP
)
1016 return implied_condition_true(expr
->unop
);
1018 if (expr
->type
== EXPR_PREOP
&& expr
->op
== SPECIAL_DECREMENT
)
1019 return implied_not_equal(expr
->unop
, 1);
1020 if (expr
->type
== EXPR_PREOP
&& expr
->op
== SPECIAL_INCREMENT
)
1021 return implied_not_equal(expr
->unop
, -1);
1023 expr
= strip_expr(expr
);
1024 switch (expr
->type
) {
1026 if (do_comparison(expr
) == 1)
1030 if (expr
->op
== '!') {
1031 if (implied_condition_false(expr
->unop
))
1037 if (implied_not_equal(expr
, 0) == 1)
1044 int implied_condition_false(struct expression
*expr
)
1046 struct expression
*tmp
;
1052 if (known_condition_false(expr
))
1055 switch (expr
->type
) {
1057 if (do_comparison(expr
) == 2)
1060 if (expr
->op
== '!') {
1061 if (implied_condition_true(expr
->unop
))
1065 tmp
= strip_expr(expr
);
1067 return implied_condition_false(tmp
);
1070 if (get_implied_value(expr
, &sval
) && sval
.value
== 0)