Linux SPARSE checker discussions
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 8/8] always evaluate both operands
Date: Fri,  2 Feb 2018 13:17:35 +0100	[thread overview]
Message-ID: <20180202121735.39621-9-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20180202121735.39621-1-luc.vanoostenryck@gmail.com>

When evaluating a binary expression, the evaluation
already stop if the left operand is found erroneous.
The right one is thus not evaluated but it may contain
another error which will only be diagnosticated after the
first one is corrected and the file rechecked.
This is especially annoying when there are several independent
errors in some complex expression since it will need several
cycles of check-edit-recheck to get all errrors out.

Fix this by always evaluating both left & right operands
(and returning NULL if one of them is erroneous).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index f63c0344d..bd10c6d9b 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3205,9 +3205,9 @@ struct symbol *evaluate_expression(struct expression *expr)
 	case EXPR_SYMBOL:
 		return evaluate_symbol_expression(expr);
 	case EXPR_BINOP:
-		if (!evaluate_expression(expr->left))
-			return NULL;
-		if (!evaluate_expression(expr->right))
+		evaluate_expression(expr->left);
+		evaluate_expression(expr->right);
+		if (!valid_subexpr_type(expr))
 			return NULL;
 		return evaluate_binop(expr);
 	case EXPR_LOGICAL:
@@ -3218,15 +3218,15 @@ struct symbol *evaluate_expression(struct expression *expr)
 			return NULL;
 		return evaluate_comma(expr);
 	case EXPR_COMPARE:
-		if (!evaluate_expression(expr->left))
-			return NULL;
-		if (!evaluate_expression(expr->right))
+		evaluate_expression(expr->left);
+		evaluate_expression(expr->right);
+		if (!valid_subexpr_type(expr))
 			return NULL;
 		return evaluate_compare(expr);
 	case EXPR_ASSIGNMENT:
-		if (!evaluate_expression(expr->left))
-			return NULL;
-		if (!evaluate_expression(expr->right))
+		evaluate_expression(expr->left);
+		evaluate_expression(expr->right);
+		if (!valid_subexpr_type(expr))
 			return NULL;
 		return evaluate_assignment(expr);
 	case EXPR_PREOP:
-- 
2.16.0


      parent reply	other threads:[~2018-02-02 12:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02 12:17 [PATCH 0/8] avoid duplicated warnings Luc Van Oostenryck
2018-02-02 12:17 ` [PATCH 1/8] add testcases for duplicated warning about invalid types Luc Van Oostenryck
2018-02-02 12:17 ` [PATCH 2/8] fix error in bad conditional Luc Van Oostenryck
2018-02-02 12:17 ` [PATCH 3/8] early return if null ctype in evaluate_conditional() Luc Van Oostenryck
2018-02-10 19:28   ` Christopher Li
2018-02-10 19:43     ` Luc Van Oostenryck
2018-02-02 12:17 ` [PATCH 4/8] add helper: valid_type() Luc Van Oostenryck
2018-02-10 19:38   ` Christopher Li
2018-02-10 19:51     ` Luc Van Oostenryck
2018-02-02 12:17 ` [PATCH 5/8] use valid_type to avoid to warn twice on conditionals Luc Van Oostenryck
2018-02-02 12:17 ` [PATCH 6/8] add helpers: valid_expr_type() & valid_subexpr_type() Luc Van Oostenryck
2018-02-02 12:17 ` [PATCH 7/8] do not report bad types twice Luc Van Oostenryck
2018-02-02 12:17 ` Luc Van Oostenryck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180202121735.39621-9-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox