From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936560AbdLRQX7 (ORCPT ); Mon, 18 Dec 2017 11:23:59 -0500 Received: from kadath.azazel.net ([81.187.231.250]:58650 "EHLO kadath.azazel.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933851AbdLRQX4 (ORCPT ); Mon, 18 Dec 2017 11:23:56 -0500 Date: Mon, 18 Dec 2017 16:23:52 +0000 From: Jeremy Sowden To: Joe Perches Cc: linux-kernel@vger.kernel.org, apw@canonical.com Subject: Re: [PATCH] checkpatch: fix for stripping brackets from macros. Message-ID: <20171218162352.GA838@azazel.net> References: <20171218141716.26227-1-jeremy@azazel.net> <1513609970.31581.62.camel@perches.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="XsQoSWH+UP9D9v3l" Content-Disposition: inline In-Reply-To: <1513609970.31581.62.camel@perches.com> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On 2017-12-18, at 07:12:50 -0800, Joe Perches wrote: > On Mon, 2017-12-18 at 14:17 +0000, Jeremy Sowden wrote: > > When checking macros, checkpatch.pl strips parentheses, square > > brackets and braces. However, the search-and-replace expression was > > not correct, and instead of replacing the brackets and their > > contents with just the contents, it was replacing them with literal > > 1's. > > Jeremy: > > What is the effect on the rest of the block that uses this substituted > $dstat? Why should this be done? I had some macros which defined compound literals, e.g.: #define TEST (struct test) { .member = 1 } and checkpatch.pl complained that macros with complex values should be enclosed in parentheses. When I had a look at the checkpatch.pl source I noticed that there were a number of exceptions against which $dstat was matched and that they included the struct and union keywords. These matches failed, however, 'cause the compound-literal had been turned into: 1 1 which didn't seem to make much sense. Given that the while-loop was immediately followed by another that did the more obvious thing: # Flatten any parentheses and braces while ($dstat =~ s/\([^\(\)]*\)/1/ || $dstat =~ s/\{[^\{\}]*\}/1/ || $dstat =~ s/.\[[^\[\]]*\]/1/) { } # Flatten any obvious string concatentation. while ($dstat =~ s/($String)\s*$Ident/$1/ || $dstat =~ s/$Ident\s*($String)/$1/) { } it occurred to me that this might be a bug. > Andy: > > I believe this is intentional as it simplifies > the macro analysis and has no other effect on the > rest of the block. Correct? > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > [] > > @@ -4874,9 +4874,9 @@ sub process { > > $dstat =~ s/\s*$//s; > > > > # Flatten any parentheses and braces > > - while ($dstat =~ s/\([^\(\)]*\)/1/ || > > - $dstat =~ s/\{[^\{\}]*\}/1/ || > > - $dstat =~ s/.\[[^\[\]]*\]/1/) > > + while ($dstat =~ s/\(([^\(\)]*)\)/$1/ || > > + $dstat =~ s/\{([^\{\}]*)\}/$1/ || > > + $dstat =~ s/.\[([^\[\]]*)\]/$1/) > > { > > } --XsQoSWH+UP9D9v3l Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEVbDTMOAK4SXP2yyD0czNNmRE1J0FAlo3648ACgkQ0czNNmRE 1J0CQA/+IL4iVdo1h4BalplRgMU53/9u2n+tM/QwszxLOboSy88i53IVqSu/ox0e QAipBi2S5IQQL2HrCBhxAc76S2y7p41DL6wwS25d4Kw/qur/56Zxaq0OelEbrBPI 0QoGWgX4hcMK8oNTH8teDLf/o1DWglmMpjxcxLLCpkPtbmRU7iI0qYROfFVc46Fn iXfAw8nl9L1MTe8pF9dpfiEQqo5G1cCPiV8T6H3oi4nne3/lmZ1Anr1MGn/v03EY YCkeN7j3sWLGSX0G3bgRKrmzCzy7GqQ1S87q7Ns7hdoTTBj8zPmP7rewWQ+cjDVg xeCvNli1uyOZPor6d+60slNQ4NLaqkuSq6Ht0xLIGr99+sf01meeaGXTeqaj+9HN zd9lM0XavXBJiCdo3LBgbhAk8jfAmZMxSbEWobmBC0BilBcjsFiEUu/nIzEL87o0 OQXLm0hDYGWrwpI5OUmyof5p+Lwq/R6cdWjl9ju9/E+wMyePEYW2bL8ycmEfrMm/ JeL6UtrKwa5zGdXsZCiX/IOE1fG8Limg3ubG7zNKb7frO7iFFld8AhNsvubc964I WJbnCJJyQ8vrN3PAk+TAQViUoISIGFe5hieErf9R49crPQ+Mr4qDG5TD8UlHjJsZ fZy33ilC2R1fRS6doKRb8xz6csKUKVd87LggEqRe6WXw5//s4TY= =xAk0 -----END PGP SIGNATURE----- --XsQoSWH+UP9D9v3l--