From patchwork Wed Aug 10 09:07:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Forbes X-Patchwork-Id: 1052252 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7A971TP003266 for ; Wed, 10 Aug 2011 09:07:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752205Ab1HJJHt (ORCPT ); Wed, 10 Aug 2011 05:07:49 -0400 Received: from mail-gx0-f174.google.com ([209.85.161.174]:35936 "EHLO mail-gx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750922Ab1HJJHs (ORCPT ); Wed, 10 Aug 2011 05:07:48 -0400 Received: by gxk21 with SMTP id 21so529189gxk.19 for ; Wed, 10 Aug 2011 02:07:48 -0700 (PDT) Received: by 10.42.135.129 with SMTP id p1mr7848648ict.37.1312967268161; Wed, 10 Aug 2011 02:07:48 -0700 (PDT) Received: from localhost.localdomain (ip-118-90-54-106.xdsl.xnet.co.nz [118.90.54.106]) by mx.google.com with ESMTPS id n14sm581369ibi.39.2011.08.10.02.07.46 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 10 Aug 2011 02:07:47 -0700 (PDT) From: Chris Forbes To: linux-sparse@vger.kernel.org Cc: Chris Forbes Subject: [PATCH 1/2] add test case for identical exprs on LHS and RHS of '&&' operator Date: Wed, 10 Aug 2011 21:07:14 +1200 Message-Id: <1312967235-23817-2-git-send-email-chrisf@ijw.co.nz> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1312967235-23817-1-git-send-email-chrisf@ijw.co.nz> References: <1312967235-23817-1-git-send-email-chrisf@ijw.co.nz> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 10 Aug 2011 09:07:50 +0000 (UTC) --- validation/check_identical_exprs_on_and.c | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) create mode 100644 validation/check_identical_exprs_on_and.c diff --git a/validation/check_identical_exprs_on_and.c b/validation/check_identical_exprs_on_and.c new file mode 100644 index 0000000..712395d --- /dev/null +++ b/validation/check_identical_exprs_on_and.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_and.c:5:15: warning: identical expressions on both sides of '&&' +check_identical_exprs_on_and.c:11:22: warning: identical expressions on both sides of '&&' + * check-error-end + */