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 7/8] do not report bad types twice
Date: Fri,  2 Feb 2018 13:17:34 +0100	[thread overview]
Message-ID: <20180202121735.39621-8-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20180202121735.39621-1-luc.vanoostenryck@gmail.com>

The type 'bad_ctype' is only used after an error has been detected.
Since this error has also been reported, there is no reasons
to issue more errors when a 'bad_ctype' is involved. This allow
to focus on the root cause of the error.

Fix this by checking in bad_expr_type() if one of the operands
is already a 'bad_ctype' and do not issue an diagnostic message
in this case.

Note: the kernel has a bunch of these situations where the
      exact same warning is given several times in a row,
      sometimes as much as a dozen time.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c                   | 7 ++++++-
 validation/bad-type-twice2.c | 1 -
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index 14922017b..f63c0344d 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -404,15 +404,20 @@ static inline int is_string_type(struct symbol *type)
 
 static struct symbol *bad_expr_type(struct expression *expr)
 {
-	sparse_error(expr->pos, "incompatible types for operation (%s)", show_special(expr->op));
 	switch (expr->type) {
 	case EXPR_BINOP:
 	case EXPR_COMPARE:
+		if (!valid_subexpr_type(expr))
+			break;
+		sparse_error(expr->pos, "incompatible types for operation (%s)", show_special(expr->op));
 		info(expr->pos, "   left side has type %s", show_typename(expr->left->ctype));
 		info(expr->pos, "   right side has type %s", show_typename(expr->right->ctype));
 		break;
 	case EXPR_PREOP:
 	case EXPR_POSTOP:
+		if (!valid_expr_type(expr->unop))
+			break;
+		sparse_error(expr->pos, "incompatible types for operation (%s)", show_special(expr->op));
 		info(expr->pos, "   argument has type %s", show_typename(expr->unop->ctype));
 		break;
 	default:
diff --git a/validation/bad-type-twice2.c b/validation/bad-type-twice2.c
index 916e82028..0aadd7a30 100644
--- a/validation/bad-type-twice2.c
+++ b/validation/bad-type-twice2.c
@@ -7,7 +7,6 @@ int foo(int x, int y)
 
 /*
  * check-name: bad-type-twice2
- * check-known-to-fail
  *
  * check-error-start
 bad-type-twice2.c:1:8: warning: 'type_t' has implicit type
-- 
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 ` Luc Van Oostenryck [this message]
2018-02-02 12:17 ` [PATCH 8/8] always evaluate both operands Luc Van Oostenryck

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-8-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