Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp7332550imm; Mon, 21 May 2018 00:31:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp24G8Qb4iJI03Cw2CWwT8Yl5fF4DFdUe13c5YdUN/NhGg9rFHVEUCBvUhc5USp9Dr4ET0d X-Received: by 2002:a65:668e:: with SMTP id b14-v6mr9635270pgw.172.1526887871354; Mon, 21 May 2018 00:31:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526887871; cv=none; d=google.com; s=arc-20160816; b=tafQk0zOQjPQJgKrFv1/lS/KWUIe9qE6MXE8zaxdo9CiTddAFZC4UgZRADgAyJDJQ5 1KV7WEL4b1Vzfud94fyJVVVjrQwYq1gBTK9OKxy4bt3PUFzfIJegj62qUsasJpFqlybS njhLEbknRAAYuFYiFrCtG196d9lCB782lAIKnTsQCopghLGkDF3XOTSM4wqv5ugRuXnd Yamennx8ihNZPRG+tIXsfU7OdhP0BVM55ifOxHUCB3d7slv0IqUGKWO4wXZV8G+rfXTl UcS14US3LNVCZ+wqQOlV2nn3/8B3AsjfqavxHELEd5Hq1kFfmvDZf0iMIlqBnZfA010G PRAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=puDtLF1et2P8NldqajuX8TrTKaYWEsNBDgrVAtBdjEQ=; b=r5Ayxg7e0ynRrC70II9rHnpcavBraygV7ozV4xHlVwMDlf7w7tcjZ//2rJh9Jg8XC6 vhSYvdOln8mWmeXiVlsswAmobOLo5oLrv+v6rQp/jKS8STcO3DcjrqXmro/ICKcDhnwm 7H4WBdQxmZFcfuxwEV4qiOjz48NJi5SW3xKKZJ1oGP9KLtC1jES3q98OOX3XRXWePd8W Fz+gsRGhZXtFCSd6SzhsseyREWvSHSdDCP6Qm9+7eQpat5FCuiQBfHOwMyBs4guoIVDQ b/kowpPgAzc/aOKmuxIgnrs2jO1ZSPlPZBmynp/ZjonMNird2j8I3Gyym7uebe6Vc54I XYwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11-v6si3909563plo.130.2018.05.21.00.30.57; Mon, 21 May 2018 00:31:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751143AbeEUHam (ORCPT + 99 others); Mon, 21 May 2018 03:30:42 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:10151 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751039AbeEUHah (ORCPT ); Mon, 21 May 2018 03:30:37 -0400 X-IronPort-AV: E=Sophos;i="5.49,426,1520895600"; d="scan'208";a="327694058" Received: from palace.rsr.lip6.fr (HELO localhost.localdomain) ([132.227.105.202]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/AES128-SHA256; 21 May 2018 09:30:35 +0200 From: Julia Lawall To: Masahiro Yamada Cc: kernel-janitors@vger.kernel.org, Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org Subject: [PATCH] coccinelle: deref_null: improve performance Date: Mon, 21 May 2018 08:58:59 +0200 Message-Id: <1526885939-1741-1-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move rules looking for some special cases of safe dereferences before the collection of NULL-tested values. The special cases are fairly rare, but somewhat costly to find, because isomorphisms create many variants of the rules. There is thus no need to search for them over and over for each NULL tested expression. Collecting them just once is sufficient and more efficient. Signed-off-by: Julia Lawall --- scripts/coccinelle/null/deref_null.cocci | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/coccinelle/null/deref_null.cocci b/scripts/coccinelle/null/deref_null.cocci index b16ccb7..cbc6184 100644 --- a/scripts/coccinelle/null/deref_null.cocci +++ b/scripts/coccinelle/null/deref_null.cocci @@ -14,18 +14,10 @@ virtual context virtual org virtual report -@ifm@ -expression *E; -statement S1,S2; -position p1; -@@ - -if@p1 ((E == NULL && ...) || ...) S1 else S2 - // The following two rules are separate, because both can match a single // expression in different ways @pr1 expression@ -expression *ifm.E; +expression E; identifier f; position p1; @@ @@ -33,7 +25,7 @@ position p1; (E != NULL && ...) ? <+...E->f@p1...+> : ... @pr2 expression@ -expression *ifm.E; +expression E; identifier f; position p2; @@ @@ -46,6 +38,14 @@ position p2; sizeof(<+...E->f@p2...+>) ) +@ifm@ +expression *E; +statement S1,S2; +position p1; +@@ + +if@p1 ((E == NULL && ...) || ...) S1 else S2 + // For org and report modes @r depends on !context && (org || report) exists@ @@ -212,16 +212,8 @@ else S3 // The following three rules are duplicates of ifm, pr1 and pr2 respectively. // It is need because the previous rule as already made a "change". -@ifm1 depends on context && !org && !report@ -expression *E; -statement S1,S2; -position p1; -@@ - -if@p1 ((E == NULL && ...) || ...) S1 else S2 - @pr11 depends on context && !org && !report expression@ -expression *ifm1.E; +expression E; identifier f; position p1; @@ @@ -229,7 +221,7 @@ position p1; (E != NULL && ...) ? <+...E->f@p1...+> : ... @pr12 depends on context && !org && !report expression@ -expression *ifm1.E; +expression E; identifier f; position p2; @@ @@ -242,6 +234,14 @@ position p2; sizeof(<+...E->f@p2...+>) ) +@ifm1 depends on context && !org && !report@ +expression *E; +statement S1,S2; +position p1; +@@ + +if@p1 ((E == NULL && ...) || ...) S1 else S2 + @depends on context && !org && !report exists@ expression subE <= ifm1.E; expression *ifm1.E;