From: Dan Carpenter Date: Thu, 11 Oct 2012 12:17:41 +0000 (+0300) Subject: math: improve how known logical operations are handled X-Git-Tag: 1.57~213 X-Git-Url: https://repo.or.cz/w/smatch.git/commitdiff_plain/df7c91199197e9a1b9a62cf5e1d516208512d248 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 --- 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;