From fe8d427480560426ba50b1363f10eed5d4a6bee3 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 20 May 2013 21:38:28 +0300 Subject: [PATCH] math: make new handle_known_binop() function Signed-off-by: Dan Carpenter --- smatch_math.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/smatch_math.c b/smatch_math.c index db18f756..c9e429da 100644 --- a/smatch_math.c +++ b/smatch_math.c @@ -434,27 +434,11 @@ static sval_t handle_mod(struct expression *expr, int *undefined, int implied) return bogus; } -static int handle_known_bitwise_AND(struct expression *expr, struct range_list **rl) -{ - sval_t left, right; - - if (!get_value(expr->left, &left)) - return 0; - if (!get_value(expr->right, &right)) - return 0; - left = sval_binop(left, '&', right); - *rl = alloc_rl(left, left); - return 1; -} - static struct range_list *handle_bitwise_AND(struct expression *expr, int implied) { struct symbol *type; struct range_list *left_rl, *right_rl; - if (handle_known_bitwise_AND(expr, &left_rl)) - return left_rl; - if (implied == EXACT || implied == HARD_MAX) return NULL; type = get_type(expr); @@ -478,6 +462,18 @@ static struct range_list *handle_bitwise_AND(struct expression *expr, int implie return rl_intersection(left_rl, right_rl); } +static struct range_list *handle_known_binop(struct expression *expr) +{ + sval_t left, right; + + if (!get_value(expr->left, &left)) + return NULL; + if (!get_value(expr->right, &right)) + return NULL; + left = sval_binop(left, expr->op, right); + return alloc_rl(left, left); +} + static struct range_list *handle_binop_rl(struct expression *expr, int implied) { struct symbol *type; @@ -485,6 +481,13 @@ static struct range_list *handle_binop_rl(struct expression *expr, int implied) sval_t ret = {.type = &int_ctype, {.value = 123456} }; int local_undef = 0; int undefined = 0; + struct range_list *rl; + + rl = handle_known_binop(expr); + if (rl) + return rl; + if (implied == EXACT) + return NULL; switch (expr->op) { case '%': -- 2.11.4.GIT