math: improve how known logical operations are handled
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 11 Oct 2012 12:17:41 +0000 (11 15:17 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Thu, 11 Oct 2012 12:17:41 +0000 (11 15:17 +0300)
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 <dan.carpenter@oracle.com>
smatch_math.c

index b0ba07e..60d5a53 100644 (file)
@@ -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;