From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753239AbcIDKK2 (ORCPT ); Sun, 4 Sep 2016 06:10:28 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:24845 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751524AbcIDKK1 (ORCPT ); Sun, 4 Sep 2016 06:10:27 -0400 X-IronPort-AV: E=Sophos;i="5.30,280,1470693600"; d="scan'208";a="235147947" Date: Sun, 4 Sep 2016 18:10:18 +0800 (SGT) From: Julia Lawall X-X-Sender: jll@hadrien To: Joe Perches cc: Dan Carpenter , LKML Subject: Re: Possible code defects: macros and precedence In-Reply-To: <1472927739.5018.13.camel@perches.com> Message-ID: References: <1472927739.5018.13.camel@perches.com> 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 On Sat, 3 Sep 2016, Joe Perches wrote: > There are many nominally incorrect macro definitions > in linux-kernel source where parentheses are not used > for various macros arguments with calculations. > > Does coccinelle or smatch have the ability to detect > potential macro misuse where arguments passed to the > macro are not correctly parenthesized by the macro? > > Something like: > > #define A 1 > #define B 2 > #define shift(val) (val << 1) > > where a use is: > > int c = shift(A | B) > > where the actual result is 5 but the expected result is 6? > > Can either tool suggest changing the macro to > > #define shift(val) ((val) << 1) Coccinelle could do this. It is possible to match macro parameters, and it is possible to match binary operators generically. I can look into it. julia