linux-sparse.vger.kernel.org archive mirror
 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/2] initial work on check for identical exprs on both sides of '&&'; needs more
Date: Wed, 10 Aug 2011 21:07:15 +1200	[thread overview]
Message-ID: <1312967235-23817-3-git-send-email-chrisf@ijw.co.nz> (raw)
In-Reply-To: <1312967235-23817-1-git-send-email-chrisf@ijw.co.nz>

---
 evaluate.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index f8343c2..af0be59 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -853,8 +853,67 @@ static struct symbol *evaluate_conditional(struct expression *expr, int iterator
 	return ctype;
 }
 
+static int are_equivalent_expr(struct expression *lhs, struct expression *rhs)
+{
+	/* recursively determine if lhs ~ rhs. */
+	if (!lhs ^ !rhs) return 0;
+
+	if (lhs->type != rhs->type) return 0;
+	if (lhs->flags != rhs->flags) return 0;
+	if (lhs->op != rhs->op) return 0;
+	if (lhs->ctype != rhs->ctype) return 0;
+
+	switch( lhs->type ) {
+	case EXPR_VALUE:
+		if (lhs->value != rhs->value) return 0;
+		if (lhs->taint != rhs->taint) return 0;
+		break;
+	case EXPR_FVALUE:
+		if (lhs->fvalue != rhs->fvalue) return 0;
+		break;
+	case EXPR_STRING:
+		if (lhs->wide != rhs->wide) return 0;
+		if (lhs->string->length != rhs->string->length) return 0;
+		if (memcmp(lhs->string->data, rhs->string->data,
+			lhs->string->length)) return 0;
+		break;
+/*	case EXPR_UNOP:	*/	/* this is mentioned in the union, but doesn't
+				actually exist */
+	case EXPR_PREOP:
+	case EXPR_POSTOP:
+		if (!are_equivalent_expr(lhs->unop, rhs->unop)) return 0;
+		if (lhs->op_value != rhs->op_value) return 0;
+		break;
+	case EXPR_SYMBOL:
+	case EXPR_TYPE:
+		if (lhs->symbol != rhs->symbol) return 0;
+		break;
+	case EXPR_BINOP:
+	case EXPR_COMMA:
+	case EXPR_COMPARE:
+	case EXPR_LOGICAL:
+	case EXPR_ASSIGNMENT:
+		if (!are_equivalent_expr(lhs->left, rhs->left)) return 0;
+		if (!are_equivalent_expr(lhs->right, rhs->right)) return 0;
+		break;
+
+		/* blah, more... */
+
+	default:
+		return 0;
+	}
+
+	return 1;
+}
+
 static struct symbol *evaluate_logical(struct expression *expr)
 {
+	if (expr->op == SPECIAL_LOGICAL_AND &&
+		are_equivalent_expr(expr->left, expr->right)) {
+		warning(expr->pos, "identical expressions on both "
+			"sides of '&&'");
+	}
+
 	if (!evaluate_conditional(expr->left, 0))
 		return NULL;
 	if (!evaluate_conditional(expr->right, 0))
-- 
1.7.4.1


  parent reply	other threads:[~2011-08-10  9:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-10  9:07 [RFC PATCH 0/2] check for identical exprs on LHS and RHS of '&&' Chris Forbes
2011-08-10  9:07 ` [PATCH 1/2] add test case for identical exprs on LHS and RHS of '&&' operator Chris Forbes
2011-08-10  9:07 ` Chris Forbes [this message]
2011-08-10 17:44 ` [RFC PATCH 0/2] check for identical exprs on LHS and RHS of '&&' Josh Triplett
2011-08-10 17:46   ` Al Viro
2011-08-12 19:34     ` Dan Carpenter
2011-08-12 19:16 ` Christopher Li

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=1312967235-23817-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).