From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.81]) by mx.groups.io with SMTP id smtpd.web12.10196.1589971658128132791 for ; Wed, 20 May 2020 03:47:38 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dCfK4y75; spf=pass (domain: redhat.com, ip: 207.211.31.81, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589971657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d9Byr+ClavbaYaSnhEBPP06nAG3y/Z6A4MpvI4lcfmI=; b=dCfK4y75J8a4UCwI3vlDKKwoSidhilDGIWn3otPLXLXjsym4bgq4JHu8sPv/eAwysd7OFs xJKGQ9d/vyX1zYMr/XIGg+gWKFN9QnX3KwdEXH5kBGl6GgJaNf2SXlGasoVZxQGJTZDMvi XRaescdy9D8AkZCfUQDoDRv1zO2iTFE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-jxtAJTXLPJOSysxalRaoXg-1; Wed, 20 May 2020 06:47:33 -0400 X-MC-Unique: jxtAJTXLPJOSysxalRaoXg-1 Received: by mail-wm1-f69.google.com with SMTP id v23so771249wmj.0 for ; Wed, 20 May 2020 03:47:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=d9Byr+ClavbaYaSnhEBPP06nAG3y/Z6A4MpvI4lcfmI=; b=JpjZJDolCFvk8GltpoPpGEiT7spw3AGxUB/uE8wy7CL4jKh6TVCdJ9jqJdC1VCJJSw y/Ls9+6tdMwVOsdXfudXa/QC1hbIbtHyePPH7LksvcS1dWgVuruSY3rtAdRZW+SCaib8 8kPD5oRWQlu8XOgubXWlW78+C11rvYaEqjGm0x5UZiqbDBODJdv1rwgoKXR6c87K6+td FC4Uirnebh2ie046Nd7Ehh4DP+ix5s+lnMOeH5/TCwm9bOXbh4mU+MdvbQmH80M48YJM V1Br4+KBjmY9yswPjKYwEKxXZxLWqCl2FjQt1Iyaq3MR+g31uZ/FLfJ8XTq8K2aTzdke arxw== X-Gm-Message-State: AOAM530vAzaLxlJi7a/EjOHN0S9Z0UZnOsI2dHl7RJIX4Q2+0O5wiYOs v/ecvyTSfT9cWy3K0Za/4jItEqrXzpvF9uPkqgHFsR7+NdkoMjXnsedC5a3H+KB2Gw8QgoJyb4r 79nzlB5a6AnDwPQ== X-Received: by 2002:a5d:43cf:: with SMTP id v15mr2285933wrr.350.1589971651302; Wed, 20 May 2020 03:47:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBV+4A8WvLDkugaZAY90ZnJBjjc3aA5Qz2kCgrXSIOXty2y1WBh0b2ekfQdWZiWUfGKV1I7w== X-Received: by 2002:a5d:43cf:: with SMTP id v15mr2285912wrr.350.1589971651054; Wed, 20 May 2020 03:47:31 -0700 (PDT) Return-Path: Received: from [192.168.1.38] (17.red-88-21-202.staticip.rima-tde.net. [88.21.202.17]) by smtp.gmail.com with ESMTPSA id h27sm2619202wrc.46.2020.05.20.03.47.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 May 2020 03:47:30 -0700 (PDT) Subject: Re: [PATCH v2 2/2] ArmPlatformPkg: Fix comparison of constants warning To: Sami Mujawar , devel@edk2.groups.io Cc: Alexei.Fedorov@arm.com, ard.biesheuvel@arm.com, leif@nuviainc.com, Matteo.Carlini@arm.com, Laura.Moretta@arm.com, nd@arm.com References: <20200518124646.45292-1-sami.mujawar@arm.com> <20200518124646.45292-3-sami.mujawar@arm.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: <5eaa5a5c-ace9-b175-a8e9-82d6c2368754@redhat.com> Date: Wed, 20 May 2020 12:47:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200518124646.45292-3-sami.mujawar@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi Sami, On 5/18/20 2:46 PM, Sami Mujawar wrote: > The VS2017 compiler reports 'warning C6326: potential > comparison of a constant with another constant' when > a fixed PCD value is compared with a constant value. > > The faulting code is as marked by '-->' below: > > --> if (FixedPcdGet32 (PL011UartInteger) != 0) { > Integer = FixedPcdGet32 (PL011UartInteger); > Fractional = FixedPcdGet32 (PL011UartFractional); > } else { > ... > > The macro FixedPcdGet32 (PL011UartInteger) evaluates > to a macro _PCD_VALUE_PL011UartInteger that is defined > by the build system to represent the UART Integer > value. Therefore, the VS2017 compiler reports the above > warning. > > In this case the warning reported by the Visual Studio > compiler does not evaluate to an issue. However, it can > be useful to detect potential issues in other scenarios. > Other compilers may either be incapable of detecting and > reporting comparison with constant warnings or may be > good at reducing false positives. So, it is definitely > useful to keep this warning enabled, and disabling it > case by case is a suitable option. > > Therefore, disable this warning for Visual studio > compilers using the pragma suppress directive that: > 'Pushes the current state of the pragma on the stack, > disables the specified warning for the next line, and > then pops the warning stack so that the pragma state > is reset.' > > Signed-off-by: Sami Mujawar > --- > > Notes: > v2: > - Update patch to selectively suppress comparison of [SAMI] > constant warning and submit as a separate series. > > v1: > - Fix comparison of constant warning reported by VS2017 [SAMI] > - Various feedbacks can be seen at: > https://edk2.groups.io/g/devel/topic/32999801#46278 > > ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c > index 2d3c279cce49304959953ec4a34b50e09a7d0045..3c915e1e8de22a0b0b4cc46d495a5a6cbc784013 100644 > --- a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c > +++ b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c > @@ -2,7 +2,7 @@ > Serial I/O Port library functions with no library constructor/destructor > > Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
> - Copyright (c) 2011 - 2019, ARM Ltd. All rights reserved.
> + Copyright (c) 2011 - 2020, ARM Ltd. All rights reserved.
> > SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -174,6 +174,14 @@ PL011UartInitializePort ( > // > > // If PL011 Integer value has been defined then always ignore the BAUD rate > +#if defined(_MSC_EXTENSIONS) > + // Suppress 'warning C6326' reported by Visual Studio compiler using > + // the suppress pragma directive that: 'Pushes the current state of > + // the pragma on the stack, disables the specified warning for the > + // next line, and then pops the warning stack so that the pragma state > + // is reset.' We don't need to document how #pragma works each time we use it in the source code... What about a simpler comment, referring the particular Visual Studio version: // // Disable 'potential comparison of a constant with another constant' // warning with VS2017 compiler static code analysis option is enabled // > +#pragma warning(suppress:6326) > +#endif > if (FixedPcdGet32 (PL011UartInteger) != 0) { > Integer = FixedPcdGet32 (PL011UartInteger); > Fractional = FixedPcdGet32 (PL011UartFractional); >