From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail04.groups.io (mail04.groups.io [45.79.224.9]) by spool.mail.gandi.net (Postfix) with ESMTPS id 953E57803CF for ; Mon, 15 Apr 2024 18:59:52 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=33wKfVL58CMHeDjjdZRybzbLVwJLFB+dMjxuWJXA3ow=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1713207591; v=1; b=JzuVEu9F/OgYDA8+FbcQyhZ8qZNieZMyi7ZP/v8J4JlyPLHsTPQWJwh9hWrURNCuPfMZ75lT PFHSSu4nsF//3Cobx7napNjBD7cs53lZTz9aHhGRe59DHZkEFk8//iisOonXBHG/ppa8uqL+w0A /uK5XPQ8X2j/+WVZ8JJNgip8vzdv9D0BKR2kR4bLrQI5kNePjAvUI2TXWOfCtkqSpBLlgWOYClz voyfpLK0eGPBYj+cp7dK5+z2yM85ib8v98ajh1SgjrwnacupWHptV/sXUs5kSymLrVpq/TWSWgF +rQd340mIunZds55nuwo1WUxLaVcbW/YC2Er4pAYfVo0A== X-Received: by 127.0.0.2 with SMTP id cGyJYY7687511x69CMEx6YQE; Mon, 15 Apr 2024 11:59:51 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.1253.1713207589863809515 for ; Mon, 15 Apr 2024 11:59:49 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B41912F4; Mon, 15 Apr 2024 12:00:17 -0700 (PDT) X-Received: from e129823.cambridge.arm.com (e129823.arm.com [10.1.197.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 03BC63F64C; Mon, 15 Apr 2024 11:59:47 -0700 (PDT) From: "levi.yun" To: devel@edk2.groups.io Cc: yeoreum.yun@arm.com, sami.mujawar@arm.com, pierre.gondois@arm.com, rebecca@bsdio.com, gaoliming@byosoft.com.cn, bob.c.feng@intel.com, yuwei.chen@intel.com, nd@arm.com Subject: [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation Date: Mon, 15 Apr 2024 19:59:47 +0100 Message-Id: <20240415185947.160172-1-yeoreum.yun@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Mon, 15 Apr 2024 11:59:49 -0700 Resent-From: yeoreum.yun@arm.com Reply-To: devel@edk2.groups.io,yeoreum.yun@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 5CcZ7WWoGmykUZUYQW71W45Nx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=JzuVEu9F; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=arm.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.9 as permitted sender) smtp.mailfrom=bounce@groups.io If a global variable is initialised using a macro with multiple arguments, ECC incorrectly parses the statement and reports the macro arguments as variable declarations. Example: In the following statement: STATIC INT WrongVariable =3D MACRO_VERSION(1, 0), NextVariable; The logic in the ECC function GetIdentifierList() interprets the above statement as declaration of three variables: 1. 'WrongVariable =3D MACRO_VERSION(1,' 2. '0)' 3. 'NextVariable' Following which NamingConventionCheckVariableName() reports an error for "0)" stating an incorrect variable declaration as below: "ERROR - *The variable name [0)] does not follow the rules" This patch fixes the parsing logic so that scenarios with macro initialisations are handled correctly. Cc: Rebecca Cran Cc: Liming Gao Cc: Bob Feng Cc: Yuwei Chen Cc: Sami Mujawar Cc: Pierre Gondois Signed-off-by: levi.yun --- The changes can be seen at https://github.com/LeviYeoReum/edk2/tree/levi/= 3057_fix_false_on_ecc_v2 BaseTools/Source/Python/Ecc/c.py | 23 ++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/Python/Ecc/c.py b/BaseTools/Source/Python/E= cc/c.py index 61ad084fcc5b85b5a2194afd8bb1a4b4b65fdaee..71dc0fcf884ee3d45a527f208= 44b697958df366c 100644 --- a/BaseTools/Source/Python/Ecc/c.py +++ b/BaseTools/Source/Python/Ecc/c.py @@ -182,8 +182,27 @@ def GetIdentifierList(): continue =20 if var.Declarator.find('{') =3D=3D -1: - for decl in var.Declarator.split(','): - DeclList =3D decl.split('=3D') + DeclText =3D var.Declarator + while (len(DeclText) > 0): + AllocatorPos =3D DeclText.find('=3D') + SplitPos =3D DeclText.find(',') + + if (SplitPos =3D=3D -1): + SplitPos =3D len(DeclText) + elif (SplitPos > AllocatorPos): + NextAllcatorPos =3D DeclText.find('=3D', AllocatorPo= s + 1) + if (NextAllcatorPos =3D=3D -1): + NextAllcatorPos =3D len(DeclText) + ParPos =3D DeclText.rfind(')', SplitPos, NextAllcato= rPos) + if (ParPos !=3D -1): + SplitPos =3D DeclText.find(',', ParPos) + if (SplitPos =3D=3D -1): + SplitPos =3D ParPos + 1 + + SubDeclText =3D DeclText[:SplitPos] + DeclText =3D DeclText[SplitPos + 1:] + + DeclList =3D SubDeclText.split('=3D') Name =3D DeclList[0].strip() if ArrayPattern.match(Name): LSBPos =3D var.Declarator.find('[') -- Guid("CE165669-3EF3-493F-B85D-6190EE5B9759") -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#117802): https://edk2.groups.io/g/devel/message/117802 Mute This Topic: https://groups.io/mt/105542888/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-