2 * smatch/smatch_capped.c
4 * Copyright (C) 2011 Oracle. All rights reserved.
6 * Licensed under the Open Software License version 1.1
11 * This is trying to make a list of the variables which
12 * have capped values. Sometimes we don't know what the
13 * cap is, for example if we are comparing variables but
14 * we don't know the values of the variables. In that
15 * case we only know that our variable is capped and we
16 * sort that information here.
20 #include "smatch_slist.h"
27 int is_capped(struct expression
*expr
)
31 if (expr
->type
== EXPR_BINOP
) {
34 if (expr
->op
== SPECIAL_RIGHTSHIFT
)
37 return is_capped(expr
->right
);
38 if (!is_capped(expr
->left
))
42 if (!is_capped(expr
->right
))
46 if (get_implied_max(expr
, &val
))
48 if (get_state_expr(my_id
, expr
) == &capped
)
53 static void match_condition(struct expression
*expr
)
55 struct smatch_state
*left_true
= NULL
;
56 struct smatch_state
*left_false
= NULL
;
57 struct smatch_state
*right_true
= NULL
;
58 struct smatch_state
*right_false
= NULL
;
61 if (expr
->type
!= EXPR_COMPARE
)
67 case SPECIAL_UNSIGNED_LT
:
68 case SPECIAL_UNSIGNED_LTE
:
70 right_false
= &capped
;
74 case SPECIAL_UNSIGNED_GT
:
75 case SPECIAL_UNSIGNED_GTE
:
83 case SPECIAL_NOTEQUAL
:
85 right_false
= &capped
;
92 set_true_false_states_expr(my_id
, expr
->right
, right_true
, right_false
);
93 set_true_false_states_expr(my_id
, expr
->left
, left_true
, left_false
);
96 static void match_min_assign(const char *fn
, struct expression
*expr
, void *unused
)
98 set_state_expr(my_id
, expr
->left
, &capped
);
101 static void match_assign(struct expression
*expr
)
103 if (is_capped(expr
->right
)) {
104 set_state_expr(my_id
, expr
->left
, &capped
);
106 if (get_state_expr(my_id
, expr
->left
))
107 set_state_expr(my_id
, expr
->left
, &uncapped
);
111 void register_capped(int id
)
115 add_hook(&match_condition
, CONDITION_HOOK
);
116 add_hook(&match_assign
, ASSIGNMENT_HOOK
);
117 add_macro_assign_hook("min", &match_min_assign
, NULL
);
118 add_macro_assign_hook("min_t", &match_min_assign
, NULL
);