All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Forbes <chrisf@ijw.co.nz>
To: linux-sparse@vger.kernel.org
Cc: Chris Forbes <chrisf@ijw.co.nz>
Subject: [PATCH 2/3] evaluate: warn on identical exprs around '||'
Date: Sun, 28 Aug 2011 10:26:54 +1200	[thread overview]
Message-ID: <1314484015-7694-2-git-send-email-chrisf@ijw.co.nz> (raw)
In-Reply-To: <1314484015-7694-1-git-send-email-chrisf@ijw.co.nz>

Same as prev, but for || operator.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
---
 evaluate.c                               |    4 ++++
 validation/check_identical_exprs_on_or.c |   24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
 create mode 100644 validation/check_identical_exprs_on_or.c

diff --git a/evaluate.c b/evaluate.c
index 08f6ae6..11de7aa 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -985,6 +985,10 @@ static struct symbol *evaluate_logical(struct expression *expr)
 			expr_equiv(expr->left, expr->right)) {
 			warning(expr->pos, "identical expressions on both "
 				"sides of '&&'");
+		} else if (expr->op == SPECIAL_LOGICAL_OR &&
+			expr_equiv(expr->left, expr->right)) {
+			warning(expr->pos, "identical expressions on both "
+				"sides of '||'");
 		}
 	}
 
diff --git a/validation/check_identical_exprs_on_or.c b/validation/check_identical_exprs_on_or.c
new file mode 100644
index 0000000..74fe226
--- /dev/null
+++ b/validation/check_identical_exprs_on_or.c
@@ -0,0 +1,24 @@
+extern void bar(void);
+
+static void foo(void *a, void *b, void *c)
+{
+	if (a || a)	/* should warn */
+		bar();
+
+	if (a || b)	/* should not warn */
+		bar();
+
+	if ((a == b) || (a == b))	/* should warn */
+		bar();
+
+	if ((a == b) || (b == c))	/* should not warn */
+		bar();
+}
+/*
+ * check-name: A warning should be issued for identical expressions on both sides of the '||' operator.
+ *
+ * check-error-start
+check_identical_exprs_on_or.c:5:15: warning: identical expressions on both sides of '||'
+check_identical_exprs_on_or.c:11:22: warning: identical expressions on both sides of '||'
+ * check-error-end
+ */
-- 
1.7.4.1


  reply	other threads:[~2011-08-27 22:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-27 22:26 [PATCH 1/3] evaluate: warn on identical exprs around '&&' Chris Forbes
2011-08-27 22:26 ` Chris Forbes [this message]
2011-08-27 22:26 ` [PATCH 3/3] evaluate: warn on identical exprs on ?: Chris Forbes
2011-08-28  2:46   ` Josh Triplett
2011-08-28  2:51     ` Chris Forbes
2011-08-28  2:50 ` [PATCH 1/3] evaluate: warn on identical exprs around '&&' Josh Triplett
2011-08-28  2:53   ` Chris Forbes
2011-08-28  3:33     ` Josh Triplett
2011-08-28  2:57   ` Chris Forbes
2011-08-28  3:36     ` Josh Triplett
2011-08-31  0:24 ` Christopher Li
2011-08-28  3:14 Chris Forbes
2011-08-28  3:14 ` [PATCH 2/3] evaluate: warn on identical exprs around '||' Chris Forbes

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=1314484015-7694-2-git-send-email-chrisf@ijw.co.nz \
    --to=chrisf@ijw.co.nz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.