Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759308AbbEEQHn (ORCPT ); Tue, 5 May 2015 12:07:43 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:54843 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2993212AbbEEOkl (ORCPT ); Tue, 5 May 2015 10:40:41 -0400 X-IronPort-AV: E=Sophos;i="5.13,373,1427752800"; d="scan'208";a="139067167" Date: Tue, 5 May 2015 16:40:20 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Nicholas Mc Guire cc: Julia Lawall , Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC] Coccinelle: Check for return not matching function signature In-Reply-To: <1430820761-28122-1-git-send-email-hofrat@osadl.org> Message-ID: References: <1430820761-28122-1-git-send-email-hofrat@osadl.org> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1323 Lines: 64 > +@match@ > +identifier f,ret; > +position p; > +type T1,T2; > +@@ > + > +T1 f(...) { > + T2 ret; > +<+... > +* return@p ret > +; > +...+> > +} Given the number of results, it may seem surprising, but I think that you are actually missing a lot of results. Becaue you require that ret be the first variable that is declared in the function. Also, you require that ret be an identifier. If you want to keep the restriction about being an identifier, you could put: @match exists@ type T1,T2; idexpression T2 ret; identifier f; @@ T1 f(...) { <+... return@p ret; ...+> } If you don't care about the identifier constraint, then you can just put T2 ret. Note also the addition of exists. There is a problem if only one path has this property. Another thing you can do is the following: @match exists@ type T1,T2; expression T1 ok; idexpression T2 ret; identifier f; @@ T1 f(...) { <+... ( return ok; | return@p ret; ) ...+> } Then Coccinelle will find the cases where the types are wrong, rather than requiring a test in python. (I haven't tested any of this) julia -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/