From 9ddd63187c5a385acd6915e3b696860ab0b3d242 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 4 May 2015 12:25:58 +0300 Subject: [PATCH] type: improve get_binop_type() In the original code it returned NULL if we didn't know either the ->left or ->right type. But actually for some situations like "1 << foo" the type of the binop is determined by the left hand side so we know the type even if we don't know the type of the right hand side. Signed-off-by: Dan Carpenter --- smatch_type.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/smatch_type.c b/smatch_type.c index 53ff44e5..1243d788 100644 --- a/smatch_type.c +++ b/smatch_type.c @@ -71,22 +71,24 @@ static struct symbol *get_binop_type(struct expression *expr) struct symbol *left, *right; left = get_type(expr->left); - right = get_type(expr->right); - - if (!left || !right) + if (!left) return NULL; - if (left->type == SYM_PTR || left->type == SYM_ARRAY) - return left; - if (right->type == SYM_PTR || right->type == SYM_ARRAY) - return right; - if (expr->op == SPECIAL_LEFTSHIFT || expr->op == SPECIAL_RIGHTSHIFT) { if (type_positive_bits(left) < 31) return &int_ctype; return left; } + if (left->type == SYM_PTR || left->type == SYM_ARRAY) + return left; + + right = get_type(expr->right); + if (!right) + return NULL; + + if (right->type == SYM_PTR || right->type == SYM_ARRAY) + return right; if (type_positive_bits(left) < 31 && type_positive_bits(right) < 31) return &int_ctype; -- 2.11.4.GIT