public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation
@ 2024-04-15 18:59 levi.yun
  2024-04-16  3:51 ` Sami Mujawar
  2024-04-16  7:37 ` PierreGondois
  0 siblings, 2 replies; 4+ messages in thread
From: levi.yun @ 2024-04-15 18:59 UTC (permalink / raw)
  To: devel
  Cc: yeoreum.yun, sami.mujawar, pierre.gondois, rebecca, gaoliming,
	bob.c.feng, yuwei.chen, nd

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 = MACRO_VERSION(1, 0), NextVariable;
The logic in the ECC function GetIdentifierList() interprets the
above statement as declaration of three variables:
    1. 'WrongVariable = 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 <rebecca@bsdio.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Pierre Gondois <pierre.gondois@arm.com>
Signed-off-by: levi.yun <yeoreum.yun@arm.com>
---

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/Ecc/c.py
index 61ad084fcc5b85b5a2194afd8bb1a4b4b65fdaee..71dc0fcf884ee3d45a527f20844b697958df366c 100644
--- a/BaseTools/Source/Python/Ecc/c.py
+++ b/BaseTools/Source/Python/Ecc/c.py
@@ -182,8 +182,27 @@ def GetIdentifierList():
             continue
 
         if var.Declarator.find('{') == -1:
-            for decl in var.Declarator.split(','):
-                DeclList = decl.split('=')
+            DeclText = var.Declarator
+            while (len(DeclText) > 0):
+                AllocatorPos = DeclText.find('=')
+                SplitPos = DeclText.find(',')
+
+                if (SplitPos == -1):
+                    SplitPos = len(DeclText)
+                elif (SplitPos > AllocatorPos):
+                    NextAllcatorPos = DeclText.find('=', AllocatorPos + 1)
+                    if (NextAllcatorPos == -1):
+                        NextAllcatorPos = len(DeclText)
+                    ParPos = DeclText.rfind(')', SplitPos, NextAllcatorPos)
+                    if (ParPos != -1):
+                        SplitPos = DeclText.find(',', ParPos)
+                        if (SplitPos == -1):
+                            SplitPos = ParPos + 1
+
+                SubDeclText = DeclText[:SplitPos]
+                DeclText = DeclText[SplitPos + 1:]
+
+                DeclList = SubDeclText.split('=')
                 Name = DeclList[0].strip()
                 if ArrayPattern.match(Name):
                     LSBPos = 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]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation
  2024-04-15 18:59 [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation levi.yun
@ 2024-04-16  3:51 ` Sami Mujawar
  2024-04-17  6:33   ` 回复: " gaoliming via groups.io
  2024-04-16  7:37 ` PierreGondois
  1 sibling, 1 reply; 4+ messages in thread
From: Sami Mujawar @ 2024-04-16  3:51 UTC (permalink / raw)
  To: devel@edk2.groups.io, rebecca@bsdio.com, gaoliming@byosoft.com.cn,
	bob.c.feng@intel.com, yuwei.chen@intel.com
  Cc: Yeo Reum Yun, Pierre Gondois, nd

Dear Maintainers,

This patch fixes an ECC tool issue that is preventing the Arm CCA patch series from passing the edk2-CI tests, see https://dev.azure.com/tianocore/edk2-ci/_build/results?buildId=122726&view=logs&j=ec42d809-3c3b-54a9-276c-e54a8b9aaee9&t=bd91c6c3-6d75-5ede-7b63-5767cf827334&l=74

Regards,

Sami Mujawar

On 16/04/2024, 00:30, "devel@edk2.groups.io <mailto:devel@edk2.groups.io> on behalf of levi.yun via groups.io" <devel@edk2.groups.io <mailto:devel@edk2.groups.io> on behalf of yeoreum.yun=arm.com@groups.io <mailto:arm.com@groups.io>> wrote:


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 = MACRO_VERSION(1, 0), NextVariable;
The logic in the ECC function GetIdentifierList() interprets the
above statement as declaration of three variables:
1. 'WrongVariable = 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 <rebecca@bsdio.com <mailto:rebecca@bsdio.com>>
Cc: Liming Gao <gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn>>
Cc: Bob Feng <bob.c.feng@intel.com <mailto:bob.c.feng@intel.com>>
Cc: Yuwei Chen <yuwei.chen@intel.com <mailto:yuwei.chen@intel.com>>
Cc: Sami Mujawar <sami.mujawar@arm.com <mailto:sami.mujawar@arm.com>>
Cc: Pierre Gondois <pierre.gondois@arm.com <mailto:pierre.gondois@arm.com>>
Signed-off-by: levi.yun <yeoreum.yun@arm.com <mailto:yeoreum.yun@arm.com>>
---


The changes can be seen at https://github.com/LeviYeoReum/edk2/tree/levi/3057_fix_false_on_ecc_v2 <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/Ecc/c.py
index 61ad084fcc5b85b5a2194afd8bb1a4b4b65fdaee..71dc0fcf884ee3d45a527f20844b697958df366c 100644
--- a/BaseTools/Source/Python/Ecc/c.py
+++ b/BaseTools/Source/Python/Ecc/c.py
@@ -182,8 +182,27 @@ def GetIdentifierList():
continue


if var.Declarator.find('{') == -1:
- for decl in var.Declarator.split(','):
- DeclList = decl.split('=')
+ DeclText = var.Declarator
+ while (len(DeclText) > 0):
+ AllocatorPos = DeclText.find('=')
+ SplitPos = DeclText.find(',')
+
+ if (SplitPos == -1):
+ SplitPos = len(DeclText)
+ elif (SplitPos > AllocatorPos):
+ NextAllcatorPos = DeclText.find('=', AllocatorPos + 1)
+ if (NextAllcatorPos == -1):
+ NextAllcatorPos = len(DeclText)
+ ParPos = DeclText.rfind(')', SplitPos, NextAllcatorPos)
+ if (ParPos != -1):
+ SplitPos = DeclText.find(',', ParPos)
+ if (SplitPos == -1):
+ SplitPos = ParPos + 1
+
+ SubDeclText = DeclText[:SplitPos]
+ DeclText = DeclText[SplitPos + 1:]
+
+ DeclList = SubDeclText.split('=')
Name = DeclList[0].strip()
if ArrayPattern.match(Name):
LSBPos = 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 <https://edk2.groups.io/g/devel/message/117802>
Mute This Topic: https://groups.io/mt/105542888/1779659 <https://groups.io/mt/105542888/1779659>
Group Owner: devel+owner@edk2.groups.io <mailto:devel+owner@edk2.groups.io>
Unsubscribe: https://edk2.groups.io/g/devel/unsub <https://edk2.groups.io/g/devel/unsub> [sami.mujawar@arm.com <mailto:sami.mujawar@arm.com>]
-=-=-=-=-=-=









-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117842): https://edk2.groups.io/g/devel/message/117842
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]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation
  2024-04-15 18:59 [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation levi.yun
  2024-04-16  3:51 ` Sami Mujawar
@ 2024-04-16  7:37 ` PierreGondois
  1 sibling, 0 replies; 4+ messages in thread
From: PierreGondois @ 2024-04-16  7:37 UTC (permalink / raw)
  To: levi.yun, devel
  Cc: sami.mujawar, rebecca, gaoliming, bob.c.feng, yuwei.chen, nd

Tested-by: Pierre Gondois <pierre.gondois@arm.com>

On 4/15/24 20:59, levi.yun wrote:
> 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 = MACRO_VERSION(1, 0), NextVariable;
> The logic in the ECC function GetIdentifierList() interprets the
> above statement as declaration of three variables:
>      1. 'WrongVariable = 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 <rebecca@bsdio.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Bob Feng <bob.c.feng@intel.com>
> Cc: Yuwei Chen <yuwei.chen@intel.com>
> Cc: Sami Mujawar <sami.mujawar@arm.com>
> Cc: Pierre Gondois <pierre.gondois@arm.com>
> Signed-off-by: levi.yun <yeoreum.yun@arm.com>
> ---
> 
> 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/Ecc/c.py
> index 61ad084fcc5b85b5a2194afd8bb1a4b4b65fdaee..71dc0fcf884ee3d45a527f20844b697958df366c 100644
> --- a/BaseTools/Source/Python/Ecc/c.py
> +++ b/BaseTools/Source/Python/Ecc/c.py
> @@ -182,8 +182,27 @@ def GetIdentifierList():
>               continue
>   
>           if var.Declarator.find('{') == -1:
> -            for decl in var.Declarator.split(','):
> -                DeclList = decl.split('=')
> +            DeclText = var.Declarator
> +            while (len(DeclText) > 0):
> +                AllocatorPos = DeclText.find('=')
> +                SplitPos = DeclText.find(',')
> +
> +                if (SplitPos == -1):
> +                    SplitPos = len(DeclText)
> +                elif (SplitPos > AllocatorPos):
> +                    NextAllcatorPos = DeclText.find('=', AllocatorPos + 1)
> +                    if (NextAllcatorPos == -1):
> +                        NextAllcatorPos = len(DeclText)
> +                    ParPos = DeclText.rfind(')', SplitPos, NextAllcatorPos)
> +                    if (ParPos != -1):
> +                        SplitPos = DeclText.find(',', ParPos)
> +                        if (SplitPos == -1):
> +                            SplitPos = ParPos + 1
> +
> +                SubDeclText = DeclText[:SplitPos]
> +                DeclText = DeclText[SplitPos + 1:]
> +
> +                DeclList = SubDeclText.split('=')
>                   Name = DeclList[0].strip()
>                   if ArrayPattern.match(Name):
>                       LSBPos = var.Declarator.find('[')
> --
> Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117855): https://edk2.groups.io/g/devel/message/117855
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]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 4+ messages in thread

* 回复: [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation
  2024-04-16  3:51 ` Sami Mujawar
@ 2024-04-17  6:33   ` gaoliming via groups.io
  0 siblings, 0 replies; 4+ messages in thread
From: gaoliming via groups.io @ 2024-04-17  6:33 UTC (permalink / raw)
  To: devel, sami.mujawar, rebecca, bob.c.feng, yuwei.chen
  Cc: 'Yeo Reum Yun', 'Pierre Gondois', 'nd'

Sami:
  I have no comments for this change. Acked-by: Liming Gao <gaoliming@byosoft.com.cn>

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Sami
> Mujawar
> 发送时间: 2024年4月16日 11:51
> 收件人: devel@edk2.groups.io; rebecca@bsdio.com;
> gaoliming@byosoft.com.cn; bob.c.feng@intel.com; yuwei.chen@intel.com
> 抄送: Yeo Reum Yun <YeoReum.Yun@arm.com>; Pierre Gondois
> <Pierre.Gondois@arm.com>; nd <nd@arm.com>
> 主题: Re: [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of
> variable initialisation
> 
> Dear Maintainers,
> 
> This patch fixes an ECC tool issue that is preventing the Arm CCA patch series
> from passing the edk2-CI tests, see
> https://dev.azure.com/tianocore/edk2-ci/_build/results?buildId=122726&vie
> w=logs&j=ec42d809-3c3b-54a9-276c-e54a8b9aaee9&t=bd91c6c3-6d75-5ed
> e-7b63-5767cf827334&l=74
> 
> Regards,
> 
> Sami Mujawar
> 
> On 16/04/2024, 00:30, "devel@edk2.groups.io <mailto:devel@edk2.groups.io>
> on behalf of levi.yun via groups.io" <devel@edk2.groups.io
> <mailto:devel@edk2.groups.io> on behalf of
> yeoreum.yun=arm.com@groups.io <mailto:arm.com@groups.io>> wrote:
> 
> 
> 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 = MACRO_VERSION(1, 0), NextVariable;
> The logic in the ECC function GetIdentifierList() interprets the
> above statement as declaration of three variables:
> 1. 'WrongVariable = 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 <rebecca@bsdio.com <mailto:rebecca@bsdio.com>>
> Cc: Liming Gao <gaoliming@byosoft.com.cn
> <mailto:gaoliming@byosoft.com.cn>>
> Cc: Bob Feng <bob.c.feng@intel.com <mailto:bob.c.feng@intel.com>>
> Cc: Yuwei Chen <yuwei.chen@intel.com <mailto:yuwei.chen@intel.com>>
> Cc: Sami Mujawar <sami.mujawar@arm.com
> <mailto:sami.mujawar@arm.com>>
> Cc: Pierre Gondois <pierre.gondois@arm.com
> <mailto:pierre.gondois@arm.com>>
> Signed-off-by: levi.yun <yeoreum.yun@arm.com
> <mailto:yeoreum.yun@arm.com>>
> ---
> 
> 
> The changes can be seen at
> https://github.com/LeviYeoReum/edk2/tree/levi/3057_fix_false_on_ecc_v2
> <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/Ecc/c.py
> index
> 61ad084fcc5b85b5a2194afd8bb1a4b4b65fdaee..71dc0fcf884ee3d45a527f20
> 844b697958df366c 100644
> --- a/BaseTools/Source/Python/Ecc/c.py
> +++ b/BaseTools/Source/Python/Ecc/c.py
> @@ -182,8 +182,27 @@ def GetIdentifierList():
> continue
> 
> 
> if var.Declarator.find('{') == -1:
> - for decl in var.Declarator.split(','):
> - DeclList = decl.split('=')
> + DeclText = var.Declarator
> + while (len(DeclText) > 0):
> + AllocatorPos = DeclText.find('=')
> + SplitPos = DeclText.find(',')
> +
> + if (SplitPos == -1):
> + SplitPos = len(DeclText)
> + elif (SplitPos > AllocatorPos):
> + NextAllcatorPos = DeclText.find('=', AllocatorPos + 1)
> + if (NextAllcatorPos == -1):
> + NextAllcatorPos = len(DeclText)
> + ParPos = DeclText.rfind(')', SplitPos, NextAllcatorPos)
> + if (ParPos != -1):
> + SplitPos = DeclText.find(',', ParPos)
> + if (SplitPos == -1):
> + SplitPos = ParPos + 1
> +
> + SubDeclText = DeclText[:SplitPos]
> + DeclText = DeclText[SplitPos + 1:]
> +
> + DeclList = SubDeclText.split('=')
> Name = DeclList[0].strip()
> if ArrayPattern.match(Name):
> LSBPos = 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
> <https://edk2.groups.io/g/devel/message/117802>
> Mute This Topic: https://groups.io/mt/105542888/1779659
> <https://groups.io/mt/105542888/1779659>
> Group Owner: devel+owner@edk2.groups.io
> <mailto:devel+owner@edk2.groups.io>
> Unsubscribe: https://edk2.groups.io/g/devel/unsub
> <https://edk2.groups.io/g/devel/unsub> [sami.mujawar@arm.com
> <mailto:sami.mujawar@arm.com>]
> -=-=-=-=-=-=
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117894): https://edk2.groups.io/g/devel/message/117894
Mute This Topic: https://groups.io/mt/105572420/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-17  6:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-15 18:59 [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation levi.yun
2024-04-16  3:51 ` Sami Mujawar
2024-04-17  6:33   ` 回复: " gaoliming via groups.io
2024-04-16  7:37 ` PierreGondois

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox