[edk2-devel] [edk2-platforms] [PATCH v3] Platform/ARM/SgiPkg: Fix constant-logical-operand clang error

Vijayenthiran Subramaniam posted 1 patch 3 years, 5 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
[edk2-devel] [edk2-platforms] [PATCH v3] Platform/ARM/SgiPkg: Fix constant-logical-operand clang error
Posted by Vijayenthiran Subramaniam 3 years, 5 months ago
Fix "use of logical '&&' with constant operand" error when built with
CLANG38 toolchain.

Reviewed-by: Thomas Abraham <thomas.abraham@arm.com>
Signed-off-by: Vijayenthiran Subramaniam <vijayenthiran.subramaniam@arm.com>
---

Changes since v2:
  - Reviewed-bys added from:
    https://edk2.groups.io/g/devel/topic/71391950#55868
  - Rebased to latest master and repost.

Changes since v1:
  - Fix Copyright year

Note:
    Fix Clan error reported by Leif in
    https://edk2.groups.io/g/devel/message/54586

 Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
index 9e5f7e70..f91724b9 100644
--- a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
+++ b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2018, ARM Ltd. All rights reserved.<BR>
+  Copyright (c) 2018-2020, ARM Limited. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -81,8 +81,8 @@ InitVirtioDevices (
   STATIC EFI_HANDLE mVirtIoNetController = NULL;
 
   // Install protocol interface for storage device
-  if ((FeaturePcdGet (PcdVirtioBlkSupported)) &&
-      (FixedPcdGet32 (PcdVirtioBlkBaseAddress))) {
+  if ((FeaturePcdGet (PcdVirtioBlkSupported) == TRUE) &&
+      (FixedPcdGet32 (PcdVirtioBlkBaseAddress) != 0)) {
     Status = gBS->InstallProtocolInterface (&mVirtIoBlkController,
                     &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
                     &mVirtioBlockDevicePath);
@@ -110,8 +110,8 @@ InitVirtioDevices (
   }
 
   // Install protocol interface for network device
-  if ((FeaturePcdGet (PcdVirtioNetSupported)) &&
-      (FixedPcdGet32 (PcdVirtioNetBaseAddress))) {
+  if ((FeaturePcdGet (PcdVirtioNetSupported) == TRUE) &&
+      (FixedPcdGet32 (PcdVirtioNetBaseAddress) != 0)) {
     Status = gBS->InstallProtocolInterface (&mVirtIoNetController,
                     &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
                     &mVirtioNetDevicePath);
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#67978): https://edk2.groups.io/g/devel/message/67978
Mute This Topic: https://groups.io/mt/78500293/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [edk2-platforms] [PATCH v3] Platform/ARM/SgiPkg: Fix constant-logical-operand clang error
Posted by Leif Lindholm 3 years, 5 months ago
On Wed, Nov 25, 2020 at 20:00:30 +0530, Vijayenthiran Subramaniam wrote:
> Fix "use of logical '&&' with constant operand" error when built with
> CLANG38 toolchain.

CLANG38 is the toolchain profile in the build system, it is highly
unlikely you are actually building with clang 3.8.
clang --version tells you the toolchain *version*.

> Reviewed-by: Thomas Abraham <thomas.abraham@arm.com>
> Signed-off-by: Vijayenthiran Subramaniam <vijayenthiran.subramaniam@arm.com>
> ---
> 
> Changes since v2:
>   - Reviewed-bys added from:
>     https://edk2.groups.io/g/devel/topic/71391950#55868
>   - Rebased to latest master and repost.
> 
> Changes since v1:
>   - Fix Copyright year
> 
> Note:
>     Fix Clan error reported by Leif in
>     https://edk2.groups.io/g/devel/message/54586
> 
>  Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> index 9e5f7e70..f91724b9 100644
> --- a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> +++ b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> @@ -1,6 +1,6 @@
>  /** @file
>  
> -  Copyright (c) 2018, ARM Ltd. All rights reserved.<BR>
> +  Copyright (c) 2018-2020, ARM Limited. All rights reserved.
>  
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>  
> @@ -81,8 +81,8 @@ InitVirtioDevices (
>    STATIC EFI_HANDLE mVirtIoNetController = NULL;
>  
>    // Install protocol interface for storage device
> -  if ((FeaturePcdGet (PcdVirtioBlkSupported)) &&
> -      (FixedPcdGet32 (PcdVirtioBlkBaseAddress))) {
> +  if ((FeaturePcdGet (PcdVirtioBlkSupported) == TRUE) &&
> +      (FixedPcdGet32 (PcdVirtioBlkBaseAddress) != 0)) {
>      Status = gBS->InstallProtocolInterface (&mVirtIoBlkController,
>                      &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
>                      &mVirtioBlockDevicePath);
> @@ -110,8 +110,8 @@ InitVirtioDevices (
>    }
>  
>    // Install protocol interface for network device
> -  if ((FeaturePcdGet (PcdVirtioNetSupported)) &&
> -      (FixedPcdGet32 (PcdVirtioNetBaseAddress))) {
> +  if ((FeaturePcdGet (PcdVirtioNetSupported) == TRUE) &&
> +      (FixedPcdGet32 (PcdVirtioNetBaseAddress) != 0)) {
>      Status = gBS->InstallProtocolInterface (&mVirtIoNetController,
>                      &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
>                      &mVirtioNetDevicePath);
> -- 
> 2.17.1
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#67992): https://edk2.groups.io/g/devel/message/67992
Mute This Topic: https://groups.io/mt/78500293/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [edk2-platforms] [PATCH v3] Platform/ARM/SgiPkg: Fix constant-logical-operand clang error
Posted by Vijayenthiran Subramaniam 3 years, 4 months ago
Hi Leif,

On Wed, Nov 25, 2020 at 5:58 PM Leif Lindholm <leif@nuviainc.com> wrote:
>
> On Wed, Nov 25, 2020 at 20:00:30 +0530, Vijayenthiran Subramaniam wrote:
> > Fix "use of logical '&&' with constant operand" error when built with
> > CLANG38 toolchain.
>
> CLANG38 is the toolchain profile in the build system, it is highly
> unlikely you are actually building with clang 3.8.
> clang --version tells you the toolchain *version*.

I will update the commit message in v3.

Thanks,
Vijay

> > Reviewed-by: Thomas Abraham <thomas.abraham@arm.com>
> > Signed-off-by: Vijayenthiran Subramaniam <vijayenthiran.subramaniam@arm.com>
> > ---
> >
> > Changes since v2:
> >   - Reviewed-bys added from:
> >     https://edk2.groups.io/g/devel/topic/71391950#55868
> >   - Rebased to latest master and repost.
> >
> > Changes since v1:
> >   - Fix Copyright year
> >
> > Note:
> >     Fix Clan error reported by Leif in
> >     https://edk2.groups.io/g/devel/message/54586
> >
> >  Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> > index 9e5f7e70..f91724b9 100644
> > --- a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> > +++ b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> > @@ -1,6 +1,6 @@
> >  /** @file
> >
> > -  Copyright (c) 2018, ARM Ltd. All rights reserved.<BR>
> > +  Copyright (c) 2018-2020, ARM Limited. All rights reserved.
> >
> >    SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> > @@ -81,8 +81,8 @@ InitVirtioDevices (
> >    STATIC EFI_HANDLE mVirtIoNetController = NULL;
> >
> >    // Install protocol interface for storage device
> > -  if ((FeaturePcdGet (PcdVirtioBlkSupported)) &&
> > -      (FixedPcdGet32 (PcdVirtioBlkBaseAddress))) {
> > +  if ((FeaturePcdGet (PcdVirtioBlkSupported) == TRUE) &&
> > +      (FixedPcdGet32 (PcdVirtioBlkBaseAddress) != 0)) {
> >      Status = gBS->InstallProtocolInterface (&mVirtIoBlkController,
> >                      &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
> >                      &mVirtioBlockDevicePath);
> > @@ -110,8 +110,8 @@ InitVirtioDevices (
> >    }
> >
> >    // Install protocol interface for network device
> > -  if ((FeaturePcdGet (PcdVirtioNetSupported)) &&
> > -      (FixedPcdGet32 (PcdVirtioNetBaseAddress))) {
> > +  if ((FeaturePcdGet (PcdVirtioNetSupported) == TRUE) &&
> > +      (FixedPcdGet32 (PcdVirtioNetBaseAddress) != 0)) {
> >      Status = gBS->InstallProtocolInterface (&mVirtIoNetController,
> >                      &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
> >                      &mVirtioNetDevicePath);
> > --
> > 2.17.1
> >
>
>
> 
>
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#68047): https://edk2.groups.io/g/devel/message/68047
Mute This Topic: https://groups.io/mt/78500293/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [edk2-platforms] [PATCH v3] Platform/ARM/SgiPkg: Fix constant-logical-operand clang error
Posted by Ard Biesheuvel 3 years, 5 months ago
On 11/25/20 3:30 PM, Vijayenthiran Subramaniam wrote:
> Fix "use of logical '&&' with constant operand" error when built with
> CLANG38 toolchain.
> 
> Reviewed-by: Thomas Abraham <thomas.abraham@arm.com>
> Signed-off-by: Vijayenthiran Subramaniam <vijayenthiran.subramaniam@arm.com>
> ---
> 
> Changes since v2:
>    - Reviewed-bys added from:
>      https://edk2.groups.io/g/devel/topic/71391950#55868
>    - Rebased to latest master and repost.
> 
> Changes since v1:
>    - Fix Copyright year
> 
> Note:
>      Fix Clan error reported by Leif in
>      https://edk2.groups.io/g/devel/message/54586
> 
>   Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> index 9e5f7e70..f91724b9 100644
> --- a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> +++ b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> @@ -1,6 +1,6 @@
>   /** @file
>   
> -  Copyright (c) 2018, ARM Ltd. All rights reserved.<BR>
> +  Copyright (c) 2018-2020, ARM Limited. All rights reserved.
>   
>     SPDX-License-Identifier: BSD-2-Clause-Patent
>   
> @@ -81,8 +81,8 @@ InitVirtioDevices (
>     STATIC EFI_HANDLE mVirtIoNetController = NULL;
>   
>     // Install protocol interface for storage device
> -  if ((FeaturePcdGet (PcdVirtioBlkSupported)) &&
> -      (FixedPcdGet32 (PcdVirtioBlkBaseAddress))) {
> +  if ((FeaturePcdGet (PcdVirtioBlkSupported) == TRUE) &&
> +      (FixedPcdGet32 (PcdVirtioBlkBaseAddress) != 0)) {

Nack

Please fix this by disabling this bogus warning in the compiler. The 
original code is perfectly reasonable, and comparing a boolean 
expression to TRUE could equally trigger a diagnostic in another 
compiler for being redundant. (The != 0 check for a UINT32 is fine)




>       Status = gBS->InstallProtocolInterface (&mVirtIoBlkController,
>                       &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
>                       &mVirtioBlockDevicePath);
> @@ -110,8 +110,8 @@ InitVirtioDevices (
>     }
>   
>     // Install protocol interface for network device
> -  if ((FeaturePcdGet (PcdVirtioNetSupported)) &&
> -      (FixedPcdGet32 (PcdVirtioNetBaseAddress))) {
> +  if ((FeaturePcdGet (PcdVirtioNetSupported) == TRUE) &&
> +      (FixedPcdGet32 (PcdVirtioNetBaseAddress) != 0)) {
>       Status = gBS->InstallProtocolInterface (&mVirtIoNetController,
>                       &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
>                       &mVirtioNetDevicePath);
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#67984): https://edk2.groups.io/g/devel/message/67984
Mute This Topic: https://groups.io/mt/78500293/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [edk2-platforms] [PATCH v3] Platform/ARM/SgiPkg: Fix constant-logical-operand clang error
Posted by Vijayenthiran Subramaniam 3 years, 4 months ago
Hi Ard,

On Wed, Nov 25, 2020 at 3:05 PM Ard Biesheuvel <ard.biesheuvel@arm.com> wrote:
>
> On 11/25/20 3:30 PM, Vijayenthiran Subramaniam wrote:
> > Fix "use of logical '&&' with constant operand" error when built with
> > CLANG38 toolchain.
> >
> > Reviewed-by: Thomas Abraham <thomas.abraham@arm.com>
> > Signed-off-by: Vijayenthiran Subramaniam <vijayenthiran.subramaniam@arm.com>
> > ---
> >
> > Changes since v2:
> >    - Reviewed-bys added from:
> >      https://edk2.groups.io/g/devel/topic/71391950#55868
> >    - Rebased to latest master and repost.
> >
> > Changes since v1:
> >    - Fix Copyright year
> >
> > Note:
> >      Fix Clan error reported by Leif in
> >      https://edk2.groups.io/g/devel/message/54586
> >
> >   Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c | 10 +++++-----
> >   1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> > index 9e5f7e70..f91724b9 100644
> > --- a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> > +++ b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> > @@ -1,6 +1,6 @@
> >   /** @file
> >
> > -  Copyright (c) 2018, ARM Ltd. All rights reserved.<BR>
> > +  Copyright (c) 2018-2020, ARM Limited. All rights reserved.
> >
> >     SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> > @@ -81,8 +81,8 @@ InitVirtioDevices (
> >     STATIC EFI_HANDLE mVirtIoNetController = NULL;
> >
> >     // Install protocol interface for storage device
> > -  if ((FeaturePcdGet (PcdVirtioBlkSupported)) &&
> > -      (FixedPcdGet32 (PcdVirtioBlkBaseAddress))) {
> > +  if ((FeaturePcdGet (PcdVirtioBlkSupported) == TRUE) &&
> > +      (FixedPcdGet32 (PcdVirtioBlkBaseAddress) != 0)) {
>
> Nack
>
> Please fix this by disabling this bogus warning in the compiler. The
> original code is perfectly reasonable, and comparing a boolean
> expression to TRUE could equally trigger a diagnostic in another
> compiler for being redundant. (The != 0 check for a UINT32 is fine)

As you suggested, Boolean comparison with TRUE is not required for
CLANG as well. But != 0 check for UINT32 is required to fix the error while
building with the CLANG toolchain profile. Would it be ok if I post another
version with just != 0 check with UNT32?

Regards,
Vijayenthiran

>
> >       Status = gBS->InstallProtocolInterface (&mVirtIoBlkController,
> >                       &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
> >                       &mVirtioBlockDevicePath);
> > @@ -110,8 +110,8 @@ InitVirtioDevices (
> >     }
> >
> >     // Install protocol interface for network device
> > -  if ((FeaturePcdGet (PcdVirtioNetSupported)) &&
> > -      (FixedPcdGet32 (PcdVirtioNetBaseAddress))) {
> > +  if ((FeaturePcdGet (PcdVirtioNetSupported) == TRUE) &&
> > +      (FixedPcdGet32 (PcdVirtioNetBaseAddress) != 0)) {
> >       Status = gBS->InstallProtocolInterface (&mVirtIoNetController,
> >                       &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
> >                       &mVirtioNetDevicePath);
> >


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#68040): https://edk2.groups.io/g/devel/message/68040
Mute This Topic: https://groups.io/mt/78500293/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [edk2-platforms] [PATCH v3] Platform/ARM/SgiPkg: Fix constant-logical-operand clang error
Posted by Ard Biesheuvel 3 years, 4 months ago
On 11/27/20 11:45 AM, Vijayenthiran Subramanian wrote:
> Hi Ard,
> 
> On Wed, Nov 25, 2020 at 3:05 PM Ard Biesheuvel <ard.biesheuvel@arm.com> wrote:
>>
>> On 11/25/20 3:30 PM, Vijayenthiran Subramaniam wrote:
>>> Fix "use of logical '&&' with constant operand" error when built with
>>> CLANG38 toolchain.
>>>
>>> Reviewed-by: Thomas Abraham <thomas.abraham@arm.com>
>>> Signed-off-by: Vijayenthiran Subramaniam <vijayenthiran.subramaniam@arm.com>
>>> ---
>>>
>>> Changes since v2:
>>>     - Reviewed-bys added from:
>>>       https://edk2.groups.io/g/devel/topic/71391950#55868
>>>     - Rebased to latest master and repost.
>>>
>>> Changes since v1:
>>>     - Fix Copyright year
>>>
>>> Note:
>>>       Fix Clan error reported by Leif in
>>>       https://edk2.groups.io/g/devel/message/54586
>>>
>>>    Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c | 10 +++++-----
>>>    1 file changed, 5 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
>>> index 9e5f7e70..f91724b9 100644
>>> --- a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
>>> +++ b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
>>> @@ -1,6 +1,6 @@
>>>    /** @file
>>>
>>> -  Copyright (c) 2018, ARM Ltd. All rights reserved.<BR>
>>> +  Copyright (c) 2018-2020, ARM Limited. All rights reserved.
>>>
>>>      SPDX-License-Identifier: BSD-2-Clause-Patent
>>>
>>> @@ -81,8 +81,8 @@ InitVirtioDevices (
>>>      STATIC EFI_HANDLE mVirtIoNetController = NULL;
>>>
>>>      // Install protocol interface for storage device
>>> -  if ((FeaturePcdGet (PcdVirtioBlkSupported)) &&
>>> -      (FixedPcdGet32 (PcdVirtioBlkBaseAddress))) {
>>> +  if ((FeaturePcdGet (PcdVirtioBlkSupported) == TRUE) &&
>>> +      (FixedPcdGet32 (PcdVirtioBlkBaseAddress) != 0)) {
>>
>> Nack
>>
>> Please fix this by disabling this bogus warning in the compiler. The
>> original code is perfectly reasonable, and comparing a boolean
>> expression to TRUE could equally trigger a diagnostic in another
>> compiler for being redundant. (The != 0 check for a UINT32 is fine)
> 
> As you suggested, Boolean comparison with TRUE is not required for
> CLANG as well. But != 0 check for UINT32 is required to fix the error while
> building with the CLANG toolchain profile. Would it be ok if I post another
> version with just != 0 check with UNT32?
> 

Yes, that is fine.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#68042): https://edk2.groups.io/g/devel/message/68042
Mute This Topic: https://groups.io/mt/78500293/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [edk2-platforms] [PATCH v3] Platform/ARM/SgiPkg: Fix constant-logical-operand clang error
Posted by Vijayenthiran Subramaniam 3 years, 5 months ago
Hi Ard,

On Wed, Nov 25, 2020 at 3:05 PM Ard Biesheuvel <ard.biesheuvel@arm.com> wrote:
>
> On 11/25/20 3:30 PM, Vijayenthiran Subramaniam wrote:
> > Fix "use of logical '&&' with constant operand" error when built with
> > CLANG38 toolchain.
> >
> > Reviewed-by: Thomas Abraham <thomas.abraham@arm.com>
> > Signed-off-by: Vijayenthiran Subramaniam <vijayenthiran.subramaniam@arm.com>
> > ---
> >
> > Changes since v2:
> >    - Reviewed-bys added from:
> >      https://edk2.groups.io/g/devel/topic/71391950#55868
> >    - Rebased to latest master and repost.
> >
> > Changes since v1:
> >    - Fix Copyright year
> >
> > Note:
> >      Fix Clan error reported by Leif in
> >      https://edk2.groups.io/g/devel/message/54586
> >
> >   Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c | 10 +++++-----
> >   1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> > index 9e5f7e70..f91724b9 100644
> > --- a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> > +++ b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/VirtioDevices.c
> > @@ -1,6 +1,6 @@
> >   /** @file
> >
> > -  Copyright (c) 2018, ARM Ltd. All rights reserved.<BR>
> > +  Copyright (c) 2018-2020, ARM Limited. All rights reserved.
> >
> >     SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> > @@ -81,8 +81,8 @@ InitVirtioDevices (
> >     STATIC EFI_HANDLE mVirtIoNetController = NULL;
> >
> >     // Install protocol interface for storage device
> > -  if ((FeaturePcdGet (PcdVirtioBlkSupported)) &&
> > -      (FixedPcdGet32 (PcdVirtioBlkBaseAddress))) {
> > +  if ((FeaturePcdGet (PcdVirtioBlkSupported) == TRUE) &&
> > +      (FixedPcdGet32 (PcdVirtioBlkBaseAddress) != 0)) {
>
> Nack
>
> Please fix this by disabling this bogus warning in the compiler. The
> original code is perfectly reasonable, and comparing a boolean
> expression to TRUE could equally trigger a diagnostic in another
> compiler for being redundant. (The != 0 check for a UINT32 is fine)

As you suggested, Boolean comparison with TRUE is not required for
CLANG as well. But != 0 check for UINT32 is required to fix the error while
building with the CLANG toolchain profile. Would it be ok if I post another
version with just != 0 check with UNT32?

Regards,
Vijayenthiran

>
> >       Status = gBS->InstallProtocolInterface (&mVirtIoBlkController,
> >                       &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
> >                       &mVirtioBlockDevicePath);
> > @@ -110,8 +110,8 @@ InitVirtioDevices (
> >     }
> >
> >     // Install protocol interface for network device
> > -  if ((FeaturePcdGet (PcdVirtioNetSupported)) &&
> > -      (FixedPcdGet32 (PcdVirtioNetBaseAddress))) {
> > +  if ((FeaturePcdGet (PcdVirtioNetSupported) == TRUE) &&
> > +      (FixedPcdGet32 (PcdVirtioNetBaseAddress) != 0)) {
> >       Status = gBS->InstallProtocolInterface (&mVirtIoNetController,
> >                       &gEfiDevicePathProtocolGuid, EFI_NATIVE_INTERFACE,
> >                       &mVirtioNetDevicePath);
> >


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#68021): https://edk2.groups.io/g/devel/message/68021
Mute This Topic: https://groups.io/mt/78500293/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-