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 sval_t
_get_value(struct expression
*expr
, int *undefined
, int implied
);
17 static sval_t
_get_implied_value(struct expression
*expr
, int *undefined
, int implied
);
21 static sval_t zero
= {.type
= &int_ctype
, {.value
= 0} };
22 static sval_t one
= {.type
= &int_ctype
, {.value
= 1} };
23 static sval_t bogus
= {.type
= &int_ctype
, {.value
= BOGUS
} };
25 static struct range_list
*rl_zero(void)
27 return alloc_rl(zero
, zero
);
30 static struct range_list
*rl_one(void)
32 return alloc_rl(one
, one
);
55 static int implied_to_rl_enum(int implied
)
76 static int opposite_implied(int implied
)
78 if (implied
== IMPLIED_MIN
)
80 if (implied
== IMPLIED_MAX
)
82 if (implied
== FUZZY_MIN
)
84 if (implied
== FUZZY_MAX
)
86 if (implied
== ABSOLUTE_MIN
)
88 if (implied
== ABSOLUTE_MAX
)
90 if (implied
== HARD_MAX
) /* we don't have a hard min. */
96 static int last_stmt_sval(struct statement
*stmt
, sval_t
*sval
)
98 struct expression
*expr
;
103 stmt
= last_ptr_list((struct ptr_list
*)stmt
->stmts
);
104 if (stmt
->type
!= STMT_EXPRESSION
)
106 expr
= stmt
->expression
;
107 if (!get_value(expr
, sval
))
112 static sval_t
handle_expression_statement(struct expression
*expr
, int *undefined
, int implied
)
114 struct statement
*stmt
;
117 stmt
= get_expression_statement(expr
);
118 if (!last_stmt_sval(stmt
, &ret
)) {
126 static sval_t
handle_ampersand(int *undefined
, int implied
)
130 ret
.type
= &ptr_ctype
;
133 if (implied
== IMPLIED_MIN
|| implied
== FUZZY_MIN
|| implied
== ABSOLUTE_MIN
)
134 return valid_ptr_min_sval
;
135 if (implied
== IMPLIED_MAX
|| implied
== FUZZY_MAX
|| implied
== ABSOLUTE_MAX
)
136 return valid_ptr_max_sval
;
142 static sval_t
handle_negate(struct expression
*expr
, int *undefined
, int implied
)
146 ret
= sval_blank(expr
->unop
);
148 if (known_condition_true(expr
->unop
)) {
153 if (implied
== EXACT
) {
158 if (implied_condition_true(expr
->unop
)) {
162 if (implied_condition_false(expr
->unop
)) {
166 if (implied
== IMPLIED_MIN
|| implied
== FUZZY_MIN
|| implied
== ABSOLUTE_MIN
) {
170 if (implied
== IMPLIED_MAX
|| implied
== FUZZY_MAX
|| implied
== ABSOLUTE_MAX
) {
178 static sval_t
handle_preop(struct expression
*expr
, int *undefined
, int implied
)
184 ret
= handle_ampersand(undefined
, implied
);
187 ret
= handle_negate(expr
, undefined
, implied
);
190 ret
= _get_value(expr
->unop
, undefined
, implied
);
191 ret
= sval_preop(ret
, '~');
192 ret
= sval_cast(get_type(expr
->unop
), ret
);
195 ret
= _get_value(expr
->unop
, undefined
, implied
);
196 ret
= sval_preop(ret
, '-');
199 ret
= _get_implied_value(expr
, undefined
, implied
);
202 ret
= handle_expression_statement(expr
, undefined
, implied
);
206 ret
= sval_blank(expr
);
208 ret
= sval_cast(get_type(expr
), ret
);
212 static sval_t
handle_divide(struct expression
*expr
, int *undefined
, int implied
)
216 left
= _get_value(expr
->left
, undefined
, implied
);
217 right
= _get_value(expr
->right
, undefined
, opposite_implied(implied
));
219 if (right
.value
== 0) {
224 return sval_binop(left
, '/', right
);
227 static sval_t
handle_subtract(struct expression
*expr
, int *undefined
, int implied
)
230 sval_t left
, right
, ret
;
231 int left_undefined
= 0;
232 int right_undefined
= 0;
233 int known_but_negative
= 0;
236 left
= _get_value(expr
->left
, &left_undefined
, implied
);
237 right
= _get_value(expr
->right
, &right_undefined
, opposite_implied(implied
));
239 if (!left_undefined
&& !right_undefined
) {
240 ret
= sval_binop(left
, '-', right
);
241 if (sval_is_negative(ret
))
242 known_but_negative
= 1;
244 return ret
; /* best case scenario */
247 comparison
= get_comparison(expr
->left
, expr
->right
);
251 type
= get_type(expr
);
253 switch (comparison
) {
255 case SPECIAL_UNSIGNED_GT
:
260 return sval_type_val(type
, 1);
264 return _get_value(expr
->left
, undefined
, implied
);
268 case SPECIAL_UNSIGNED_GTE
:
273 return sval_type_val(type
, 0);
277 return _get_value(expr
->left
, undefined
, implied
);
282 if (known_but_negative
)
290 static sval_t
handle_mod(struct expression
*expr
, int *undefined
, int implied
)
294 /* if we can't figure out the right side it's probably hopeless */
295 right
= _get_value(expr
->right
, undefined
, implied
);
296 if (*undefined
|| right
.value
== 0) {
304 left
= _get_value(expr
->left
, undefined
, implied
);
306 return sval_binop(left
, '%', right
);
312 return sval_type_val(get_type(expr
), 0);
317 right
= sval_cast(get_type(expr
), right
);
324 static sval_t
handle_binop(struct expression
*expr
, int *undefined
, int implied
)
328 sval_t ret
= {.type
= &int_ctype
, {.value
= 123456} };
333 return handle_mod(expr
, undefined
, implied
);
335 if (implied
== HARD_MAX
) {
339 left
= _get_value(expr
->left
, &local_undef
, implied
);
341 if (implied
== IMPLIED_MIN
|| implied
== ABSOLUTE_MIN
) {
342 ret
= sval_blank(expr
->left
);
346 if (implied
!= IMPLIED_MAX
&& implied
!= ABSOLUTE_MAX
)
348 if (!get_absolute_max(expr
->left
, &left
))
351 right
= _get_value(expr
->right
, undefined
, implied
);
354 return sval_binop(left
, '&', right
);
356 case SPECIAL_RIGHTSHIFT
:
357 if (implied
== HARD_MAX
) {
361 left
= _get_value(expr
->left
, &local_undef
, implied
);
363 if (implied
== IMPLIED_MIN
|| implied
== ABSOLUTE_MIN
) {
364 ret
= sval_blank(expr
->left
);
368 if (implied
!= IMPLIED_MAX
&& implied
!= ABSOLUTE_MAX
)
370 if (!get_absolute_max(expr
->left
, &left
))
373 right
= _get_value(expr
->right
, undefined
, implied
);
376 return sval_binop(left
, SPECIAL_RIGHTSHIFT
, right
);
378 return handle_subtract(expr
, undefined
, implied
);
381 left
= _get_value(expr
->left
, undefined
, implied
);
382 right
= _get_value(expr
->right
, undefined
, implied
);
387 type
= get_type(expr
);
388 left
= sval_cast(type
, left
);
389 right
= sval_cast(type
, right
);
394 if (sval_binop_overflows(left
, expr
->op
, right
))
395 return sval_type_max(get_type(expr
));
399 if (sval_binop_overflows(left
, expr
->op
, right
)) {
407 return handle_divide(expr
, undefined
, implied
);
409 if (right
.value
== 0) {
413 return sval_binop(left
, '%', right
);
416 ret
= sval_binop(left
, expr
->op
, right
);
421 static int do_comparison(struct expression
*expr
)
423 struct range_list
*left_ranges
= NULL
;
424 struct range_list
*right_ranges
= NULL
;
425 int poss_true
, poss_false
;
428 type
= get_type(expr
);
430 get_implied_rl(expr
->left
, &left_ranges
);
431 get_implied_rl(expr
->right
, &right_ranges
);
432 left_ranges
= cast_rl(type
, left_ranges
);
433 right_ranges
= cast_rl(type
, right_ranges
);
435 poss_true
= possibly_true_rl(left_ranges
, expr
->op
, right_ranges
);
436 poss_false
= possibly_false_rl(left_ranges
, expr
->op
, right_ranges
);
438 free_rl(&left_ranges
);
439 free_rl(&right_ranges
);
441 if (!poss_true
&& !poss_false
)
443 if (poss_true
&& !poss_false
)
445 if (!poss_true
&& poss_false
)
450 static struct range_list
*handle_comparison_rl(struct expression
*expr
, int implied
)
455 if (get_value(expr
->left
, &left
) && get_value(expr
->right
, &right
)) {
456 struct data_range tmp_left
, tmp_right
;
460 tmp_right
.min
= right
;
461 tmp_right
.max
= right
;
462 if (true_comparison_range(&tmp_left
, expr
->op
, &tmp_right
))
467 if (implied
== EXACT
)
470 res
= do_comparison(expr
);
476 return alloc_rl(zero
, one
);
479 static sval_t
handle_comparison(struct expression
*expr
, int *undefined
, int implied
)
484 if (get_value(expr
->left
, &left
) && get_value(expr
->right
, &right
)) {
485 struct data_range tmp_left
, tmp_right
;
489 tmp_right
.min
= right
;
490 tmp_right
.max
= right
;
491 if (true_comparison_range(&tmp_left
, expr
->op
, &tmp_right
))
496 if (implied
== EXACT
) {
501 res
= do_comparison(expr
);
507 if (implied
== IMPLIED_MIN
|| implied
== FUZZY_MIN
|| implied
== ABSOLUTE_MIN
)
509 if (implied
== IMPLIED_MAX
|| implied
== FUZZY_MAX
|| implied
== ABSOLUTE_MAX
)
516 static struct range_list
*handle_logical_rl(struct expression
*expr
, int implied
)
522 if (implied
== EXACT
) {
523 if (get_value(expr
->left
, &left
))
525 if (get_value(expr
->right
, &right
))
528 if (get_implied_value(expr
->left
, &left
))
530 if (get_implied_value(expr
->right
, &right
))
535 case SPECIAL_LOGICAL_OR
:
536 if (left_known
&& left
.value
)
538 if (right_known
&& right
.value
)
540 if (left_known
&& right_known
)
543 case SPECIAL_LOGICAL_AND
:
544 if (left_known
&& right_known
) {
545 if (left
.value
&& right
.value
)
554 if (implied
== EXACT
)
557 return alloc_rl(zero
, one
);
560 static sval_t
handle_logical(struct expression
*expr
, int *undefined
, int implied
)
566 if (implied
== EXACT
) {
567 if (get_value(expr
->left
, &left
))
569 if (get_value(expr
->right
, &right
))
572 if (get_implied_value(expr
->left
, &left
))
574 if (get_implied_value(expr
->right
, &right
))
579 case SPECIAL_LOGICAL_OR
:
580 if (left_known
&& left
.value
)
582 if (right_known
&& right
.value
)
584 if (left_known
&& right_known
)
587 case SPECIAL_LOGICAL_AND
:
588 if (left_known
&& right_known
) {
589 if (left
.value
&& right
.value
)
599 if (implied
== IMPLIED_MIN
|| implied
== FUZZY_MIN
|| implied
== ABSOLUTE_MIN
)
601 if (implied
== IMPLIED_MAX
|| implied
== FUZZY_MAX
|| implied
== ABSOLUTE_MAX
)
608 static struct range_list
*handle_conditional_rl(struct expression
*expr
, int implied
)
610 struct range_list
*true_rl
, *false_rl
;
612 if (known_condition_true(expr
->conditional
))
613 return _get_rl(expr
->cond_true
, implied
);
614 if (known_condition_false(expr
->conditional
))
615 return _get_rl(expr
->cond_false
, implied
);
617 if (implied
== EXACT
)
620 if (implied_condition_true(expr
->conditional
))
621 return _get_rl(expr
->cond_true
, implied
);
622 if (implied_condition_false(expr
->conditional
))
623 return _get_rl(expr
->cond_false
, implied
);
625 true_rl
= _get_rl(expr
->cond_true
, implied
);
628 false_rl
= _get_rl(expr
->cond_false
, implied
);
632 return rl_union(true_rl
, false_rl
);
635 static sval_t
handle_conditional(struct expression
*expr
, int *undefined
, int implied
)
637 if (known_condition_true(expr
->conditional
))
638 return _get_value(expr
->cond_true
, undefined
, implied
);
639 if (known_condition_false(expr
->conditional
))
640 return _get_value(expr
->cond_false
, undefined
, implied
);
642 if (implied
== EXACT
) {
647 if (implied_condition_true(expr
->conditional
))
648 return _get_value(expr
->cond_true
, undefined
, implied
);
649 if (implied_condition_false(expr
->conditional
))
650 return _get_value(expr
->cond_false
, undefined
, implied
);
656 static int get_local_value(struct expression
*expr
, sval_t
*sval
, int implied
)
665 return get_local_min_helper(expr
, sval
);
670 return get_local_max_helper(expr
, sval
);
675 static int get_implied_value_helper(struct expression
*expr
, sval_t
*sval
, int implied
)
677 struct smatch_state
*state
;
681 /* fixme: this should return the casted value */
683 expr
= strip_expr(expr
);
685 if (get_value(expr
, sval
))
688 name
= expr_to_var_sym(expr
, &sym
);
691 *sval
= sval_blank(expr
);
692 state
= get_state(SMATCH_EXTRA
, name
, sym
);
694 if (!state
|| !state
->data
)
695 return get_local_value(expr
, sval
, implied
);
696 if (implied
== IMPLIED
) {
697 if (estate_get_single_value(state
, sval
))
701 if (implied
== HARD_MAX
) {
702 if (estate_get_hard_max(state
, sval
))
706 if (implied
== IMPLIED_MAX
|| implied
== ABSOLUTE_MAX
) {
707 *sval
= estate_max(state
);
710 *sval
= estate_min(state
);
714 static int get_fuzzy_max_helper(struct expression
*expr
, sval_t
*max
)
717 struct sm_state
*tmp
;
720 if (get_hard_max(expr
, &sval
)) {
725 sm
= get_sm_state_expr(SMATCH_EXTRA
, expr
);
729 sval
= sval_type_min(estate_type(sm
->state
));
730 FOR_EACH_PTR(sm
->possible
, tmp
) {
733 new_min
= estate_min(tmp
->state
);
734 if (sval_cmp(new_min
, sval
) > 0)
736 } END_FOR_EACH_PTR(tmp
);
738 if (sval_is_min(sval
))
740 if (sval
.value
== sval_type_min(sval
.type
).value
+ 1) /* it's common to be on off */
743 *max
= sval_cast(get_type(expr
), sval
);
747 static int get_fuzzy_min_helper(struct expression
*expr
, sval_t
*min
)
750 struct sm_state
*tmp
;
753 sm
= get_sm_state_expr(SMATCH_EXTRA
, expr
);
757 if (!sval_is_min(estate_min(sm
->state
))) {
758 *min
= estate_min(sm
->state
);
762 sval
= sval_type_max(estate_type(sm
->state
));
763 FOR_EACH_PTR(sm
->possible
, tmp
) {
766 new_max
= estate_max(tmp
->state
);
767 if (sval_cmp(new_max
, sval
) < 0)
769 } END_FOR_EACH_PTR(tmp
);
771 if (sval_is_max(sval
))
773 *min
= sval_cast(get_type(expr
), sval
);
777 static int get_const_value(struct expression
*expr
, sval_t
*sval
)
782 if (expr
->type
!= EXPR_SYMBOL
|| !expr
->symbol
)
785 if (!(sym
->ctype
.modifiers
& MOD_CONST
))
787 if (get_value(sym
->initializer
, &right
)) {
788 *sval
= sval_cast(get_type(expr
), right
);
794 static struct range_list
*handle_variable(struct expression
*expr
, int implied
)
796 struct smatch_state
*state
;
797 struct range_list
*rl
;
798 sval_t sval
, min
, max
;
800 if (get_const_value(expr
, &sval
))
801 return alloc_rl(sval
, sval
);
803 switch (implied_to_rl_enum(implied
)) {
809 state
= get_state_expr(SMATCH_EXTRA
, expr
);
810 if (!state
|| !state
->data
) {
811 if (get_local_rl(expr
, &rl
))
815 if (implied
== HARD_MAX
&& !estate_has_hard_max(state
))
817 return estate_rl(state
);
819 if (!get_fuzzy_min_helper(expr
, &min
))
820 min
= sval_type_min(get_type(expr
));
821 if (!get_fuzzy_max_helper(expr
, &max
))
823 return alloc_rl(min
, max
);
828 static sval_t
_get_implied_value(struct expression
*expr
, int *undefined
, int implied
)
832 ret
= sval_blank(expr
);
841 if (!get_implied_value_helper(expr
, &ret
, implied
))
845 if (!get_fuzzy_max_helper(expr
, &ret
))
849 if (!get_fuzzy_min_helper(expr
, &ret
))
858 static sval_t
handle_sizeof(struct expression
*expr
)
863 ret
= sval_blank(expr
);
864 sym
= expr
->cast_type
;
866 sym
= evaluate_expression(expr
->cast_expression
);
868 * Expressions of restricted types will possibly get
869 * promoted - check that here
871 if (is_restricted_type(sym
)) {
872 if (sym
->bit_size
< bits_in_int
)
874 } else if (is_fouled_type(sym
)) {
878 examine_symbol_type(sym
);
880 ret
.type
= size_t_ctype
;
881 if (sym
->bit_size
<= 0) /* sizeof(void) */ {
882 if (get_real_base_type(sym
) == &void_ctype
)
887 ret
.value
= bits_to_bytes(sym
->bit_size
);
892 static struct range_list
*handle_call_rl(struct expression
*expr
, int implied
)
894 struct range_list
*rl
;
896 if (implied
== EXACT
)
899 if (get_implied_return(expr
, &rl
))
901 return db_return_vals(expr
);
904 static sval_t
handle_call(struct expression
*expr
, int *undefined
, int implied
)
906 struct range_list
*rl
;
908 if (!get_implied_rl(expr
, &rl
)) {
915 if (sval_cmp(rl_min(rl
), rl_max(rl
)) == 0)
934 static struct range_list
*_get_rl(struct expression
*expr
, int implied
)
936 struct range_list
*rl
;
941 expr
= strip_parens(expr
);
944 type
= get_type(expr
);
947 switch (expr
->type
) {
949 sval
= sval_from_val(expr
, expr
->value
);
952 sval
= handle_preop(expr
, &undefined
, implied
);
955 sval
= _get_value(expr
->unop
, &undefined
, implied
);
958 case EXPR_FORCE_CAST
:
959 case EXPR_IMPLIED_CAST
:
960 rl
= _get_rl(expr
->cast_expression
, implied
);
964 return cast_rl(type
, rl
);
967 sval
= handle_binop(expr
, &undefined
, implied
);
970 rl
= handle_comparison_rl(expr
, implied
);
976 rl
= handle_logical_rl(expr
, implied
);
983 sval
= handle_sizeof(expr
);
986 case EXPR_CONDITIONAL
:
987 rl
= handle_conditional_rl(expr
, implied
);
993 rl
= handle_call_rl(expr
, implied
);
1000 rl
= handle_variable(expr
, implied
);
1007 if (undefined
&& type
&&
1008 (implied
== ABSOLUTE_MAX
|| implied
== ABSOLUTE_MIN
))
1009 return alloc_whole_rl(type
);
1012 rl
= alloc_rl(sval
, sval
);
1016 static sval_t
_get_value(struct expression
*expr
, int *undefined
, int implied
)
1018 struct symbol
*type
;
1028 expr
= strip_parens(expr
);
1029 type
= get_type(expr
);
1031 switch (expr
->type
) {
1033 ret
= sval_from_val(expr
, expr
->value
);
1036 ret
= handle_preop(expr
, undefined
, implied
);
1039 ret
= _get_value(expr
->unop
, undefined
, implied
);
1042 case EXPR_FORCE_CAST
:
1043 case EXPR_IMPLIED_CAST
:
1044 ret
= _get_value(expr
->cast_expression
, undefined
, implied
);
1045 ret
= sval_cast(type
, ret
);
1048 ret
= handle_binop(expr
, undefined
, implied
);
1051 ret
= handle_comparison(expr
, undefined
, implied
);
1054 ret
= handle_logical(expr
, undefined
, implied
);
1056 case EXPR_PTRSIZEOF
:
1058 ret
= handle_sizeof(expr
);
1061 if (get_const_value(expr
, &ret
)) {
1064 ret
= _get_implied_value(expr
, undefined
, implied
);
1067 case EXPR_CONDITIONAL
:
1068 ret
= handle_conditional(expr
, undefined
, implied
);
1071 ret
= handle_call(expr
, undefined
, implied
);
1074 ret
= _get_implied_value(expr
, undefined
, implied
);
1082 /* returns 1 if it can get a value literal or else returns 0 */
1083 int get_value(struct expression
*expr
, sval_t
*sval
)
1085 struct range_list
*rl
;
1087 rl
= _get_rl(expr
, EXACT
);
1088 if (!rl_to_sval(rl
, sval
))
1093 int get_implied_value(struct expression
*expr
, sval_t
*sval
)
1095 struct range_list
*rl
;
1097 rl
= _get_rl(expr
, IMPLIED
);
1098 if (!rl_to_sval(rl
, sval
))
1103 int get_implied_min(struct expression
*expr
, sval_t
*sval
)
1105 struct range_list
*rl
;
1107 rl
= _get_rl(expr
, IMPLIED_MIN
);
1114 int get_implied_max(struct expression
*expr
, sval_t
*sval
)
1116 struct range_list
*rl
;
1118 rl
= _get_rl(expr
, IMPLIED_MAX
);
1125 int get_implied_rl(struct expression
*expr
, struct range_list
**rl
)
1128 struct smatch_state
*state
;
1135 expr
= strip_parens(expr
);
1139 state
= get_state_expr(SMATCH_EXTRA
, expr
);
1141 *rl
= clone_rl(estate_rl(state
));
1145 if (expr
->type
== EXPR_CALL
) {
1146 if (get_implied_return(expr
, rl
))
1148 *rl
= db_return_vals(expr
);
1154 if (get_implied_value(expr
, &sval
)) {
1155 add_range(rl
, sval
, sval
);
1159 if (get_local_rl(expr
, rl
))
1162 min_known
= get_implied_min(expr
, &min
);
1163 max_known
= get_implied_max(expr
, &max
);
1164 if (!min_known
&& !max_known
)
1167 get_absolute_min(expr
, &min
);
1169 get_absolute_max(expr
, &max
);
1171 *rl
= alloc_rl(min
, max
);
1175 int get_hard_max(struct expression
*expr
, sval_t
*sval
)
1177 struct range_list
*rl
;
1179 rl
= _get_rl(expr
, HARD_MAX
);
1186 int get_fuzzy_min(struct expression
*expr
, sval_t
*sval
)
1188 struct range_list
*rl
;
1190 rl
= _get_rl(expr
, FUZZY_MIN
);
1197 int get_fuzzy_max(struct expression
*expr
, sval_t
*sval
)
1199 struct range_list
*rl
;
1202 rl
= _get_rl(expr
, FUZZY_MAX
);
1206 if (max
.uvalue
> INT_MAX
- 10000)
1212 int get_absolute_min(struct expression
*expr
, sval_t
*sval
)
1214 struct range_list
*rl
;
1215 struct symbol
*type
;
1217 type
= get_type(expr
);
1219 type
= &llong_ctype
; // FIXME: this is wrong but places assume get type can't fail.
1220 rl
= _get_rl(expr
, ABSOLUTE_MIN
);
1224 *sval
= sval_type_min(type
);
1226 if (sval_cmp(*sval
, sval_type_min(type
)) < 0)
1227 *sval
= sval_type_min(type
);
1231 int get_absolute_max(struct expression
*expr
, sval_t
*sval
)
1233 struct range_list
*rl
;
1234 struct symbol
*type
;
1236 type
= get_type(expr
);
1238 type
= &llong_ctype
;
1239 rl
= _get_rl(expr
, ABSOLUTE_MAX
);
1243 *sval
= sval_type_max(type
);
1245 if (sval_cmp(sval_type_max(type
), *sval
) < 0)
1246 *sval
= sval_type_max(type
);
1250 int known_condition_true(struct expression
*expr
)
1257 if (get_value(expr
, &tmp
) && tmp
.value
)
1263 int known_condition_false(struct expression
*expr
)
1271 if (expr
->type
== EXPR_CALL
) {
1272 if (sym_name_is("__builtin_constant_p", expr
->fn
))
1278 int implied_condition_true(struct expression
*expr
)
1285 if (known_condition_true(expr
))
1287 if (get_implied_value(expr
, &tmp
) && tmp
.value
)
1290 if (expr
->type
== EXPR_POSTOP
)
1291 return implied_condition_true(expr
->unop
);
1293 if (expr
->type
== EXPR_PREOP
&& expr
->op
== SPECIAL_DECREMENT
)
1294 return implied_not_equal(expr
->unop
, 1);
1295 if (expr
->type
== EXPR_PREOP
&& expr
->op
== SPECIAL_INCREMENT
)
1296 return implied_not_equal(expr
->unop
, -1);
1298 expr
= strip_expr(expr
);
1299 switch (expr
->type
) {
1301 if (do_comparison(expr
) == 1)
1305 if (expr
->op
== '!') {
1306 if (implied_condition_false(expr
->unop
))
1312 if (implied_not_equal(expr
, 0) == 1)
1319 int implied_condition_false(struct expression
*expr
)
1321 struct expression
*tmp
;
1327 if (known_condition_false(expr
))
1330 switch (expr
->type
) {
1332 if (do_comparison(expr
) == 2)
1335 if (expr
->op
== '!') {
1336 if (implied_condition_true(expr
->unop
))
1340 tmp
= strip_expr(expr
);
1342 return implied_condition_false(tmp
);
1345 if (get_implied_value(expr
, &sval
) && sval
.value
== 0)