From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754101AbcICSgU (ORCPT ); Sat, 3 Sep 2016 14:36:20 -0400 Received: from smtprelay0206.hostedemail.com ([216.40.44.206]:59703 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753091AbcICSgT (ORCPT ); Sat, 3 Sep 2016 14:36:19 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:355:379:541:960:988:989:1260:1277:1311:1313:1314:1345:1373:1437:1515:1516:1518:1534:1538:1593:1594:1711:1714:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3351:3865:3867:3870:3871:5007:7903:7904:10004:10400:10848:11658:11914:13069:13153:13161:13228:13229:13311:13357:13439:14659:14721:21080:21451:30012:30054,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: bike66_6bd5269c5623a X-Filterd-Recvd-Size: 1228 Message-ID: <1472927739.5018.13.camel@perches.com> Subject: Possible code defects: macros and precedence From: Joe Perches To: Julia Lawall , Dan Carpenter Cc: LKML Date: Sat, 03 Sep 2016 11:35:39 -0700 Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) ?