From df7c91199197e9a1b9a62cf5e1d516208512d248 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 11 Oct 2012 15:17:41 +0300 Subject: [PATCH] math: improve how known logical operations are handled If we the logical operation is known to be true or false then use 1 or 0. Perhaps this is a config option or something like that. Signed-off-by: Dan Carpenter --- smatch_math.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/smatch_math.c b/smatch_math.c index b0ba07e4..60d5a535 100644 --- a/smatch_math.c +++ b/smatch_math.c @@ -275,14 +275,10 @@ static long long handle_logical(struct expression *expr, int *undefined, int imp { long long left_val, right_val; - /* TODO: we should be able to handle this... */ - if (implied == NOTIMPLIED) { - *undefined = 1; - return BOGUS; - } - - if (get_implied_value(expr->left, &left_val) && - get_implied_value(expr->right, &right_val)) { + if ((implied == NOTIMPLIED && get_value(expr->left, &left_val) && + get_value(expr->right, &right_val)) || + (implied != NOTIMPLIED && get_implied_value(expr->left, &left_val) && + get_implied_value(expr->right, &right_val))) { switch (expr->op) { case SPECIAL_LOGICAL_OR: return left_val || right_val; -- 2.11.4.GIT