From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 2051D1F4B4 for ; Wed, 9 Sep 2020 19:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbgIITNt (ORCPT ); Wed, 9 Sep 2020 15:13:49 -0400 Received: from cloud.peff.net ([104.130.231.41]:52520 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725772AbgIITNr (ORCPT ); Wed, 9 Sep 2020 15:13:47 -0400 Received: (qmail 6957 invoked by uid 109); 9 Sep 2020 19:13:46 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Wed, 09 Sep 2020 19:13:46 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 4753 invoked by uid 111); 9 Sep 2020 19:13:46 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 09 Sep 2020 15:13:46 -0400 Authentication-Results: peff.net; auth=none Date: Wed, 9 Sep 2020 15:13:45 -0400 From: Jeff King To: Edmundo Carmona Antoranz Cc: Derrick Stolee , =?utf-8?B?UmVuw6k=?= Scharfe , whydoubt@gmail.com, Git List Subject: Re: [PATCH] blame.c: replace instance of !oidcmp for oideq Message-ID: <20200909191345.GA2511547@coredump.intra.peff.net> References: <20200907171639.766547-1-eantoranz@gmail.com> <20200909091149.GB2496536@coredump.intra.peff.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Wed, Sep 09, 2020 at 08:00:57AM -0600, Edmundo Carmona Antoranz wrote: > On Wed, Sep 9, 2020 at 3:11 AM Jeff King wrote: > > > > Yeah, it looks obviously correct. I am puzzled why "make coccicheck" > > doesn't find this, though. +cc René, as my favorite target for > > coccinelle nerd-snipes. :) > > > > I added this to contrib/coccinelle/object_id.cocci in v2.27.0 > > @@ > identifier f != oideq; > expression E1, E2; > @@ > - !oidcmp(E1, E2) > + oideq(E1, E2) > > And it found it: Interesting. The existing rule is: struct object_id *OIDPTR1; struct object_id *OIDPTR2; @@ - oidcmp(OIDPTR1, OIDPTR2) == 0 + oideq(OIDPTR1, OIDPTR2) The "== 0" part looks like it might be significant, but it's not. Coccinelle knows that "!foo" is the same as "foo == 0" (and you can confirm by tweaking it). The addition of "identifer f != oideq" here isn't necessary (we don't even define an "f" in the semantic patch part). And anyway, we use hasheq() inside oideq(), so no need to override the rule there. So the relevant part is probably that our existing rule specifies the exact type, whereas your rule allows any expression. And indeed, if I do this, it works: diff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci index ddf4f22bd7..62a6cee0eb 100644 --- a/contrib/coccinelle/object_id.cocci +++ b/contrib/coccinelle/object_id.cocci @@ -55,8 +55,8 @@ struct object_id OID; + oidcmp(&OID, OIDPTR) @@ -struct object_id *OIDPTR1; -struct object_id *OIDPTR2; +expression OIDPTR1; +expression OIDPTR2; @@ - oidcmp(OIDPTR1, OIDPTR2) == 0 + oideq(OIDPTR1, OIDPTR2) Which really _seems_ like a bug in coccinelle, unless I am missing something. Because both of those parameters look like object_id pointers (and the compiler would be complaining if it were not the case). But I also wonder if giving the specific types in the coccinelle rule is buying us anything. If you passed two void pointers or ints or whatever to !oidcmp(), we'd still want to rewrite it as oideq(). -Peff