From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web09.23229.1574339998860209255 for ; Thu, 21 Nov 2019 04:39:59 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=jhKU6CNl; spf=pass (domain: linaro.org, ip: 209.85.221.66, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wr1-f66.google.com with SMTP id i12so4172716wrn.11 for ; Thu, 21 Nov 2019 04:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=m4Ec6XTTYcHFOAybi6WTqy9fLcsUEupPKygk4RlyUd0=; b=jhKU6CNlv3jd3VRKvXD0/V4jWTJngEwoOVHrlPxrRyvFq0pXva2/682JmmaqaJGzll 12OM+JGkwsYBRICTIePUe5i4u0xwnh9oIxT+sn7ZpeMuepMVsweez0nOoK5bgdhG+1f0 6PjXPAdte0l7/DgIR1xkFW46mjuCXzMYB/uexvvQHYARMJQAwPo68fbJBMbpdZ7RhIxD lczDQ/kBWG4llVDEPiQuuj3lhXupn7rAC25LzqR/Z+aLryPVS5hrZF56Ov8QqVPVsyL0 OS+ImeVMW1EzHqYx1C9j+nP6Z6hnHLvOBqknC8TvjsFhdmllWuZMw/OzYK1LE7owGqa4 zqNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=m4Ec6XTTYcHFOAybi6WTqy9fLcsUEupPKygk4RlyUd0=; b=fvMl6rdoOedZi62DJ5gaqU/vIp+H+D7gDAsNT13yR4S65c/oxNxpwNFG2NU+mYVpuY JypbgreAOaunsBc2MDjNk+lLP86dzDcnzgzycT4CtYaKEUvKTHiflOAvzcOsa/nhO5hm CGIzugJqyD5wS0vg69XsxIYWt2kowXVscxXzLmYqFoGVoisAx3vUFdVTSWQXYgQ8ptfD t3Ts2Ate4KeCDvCcV6nKdX6lYnKlx31n2lbJAsgzb6Mh51HllZKa4qUyew9GE0t9JVUv 7cxppXHvzmBf1ago8rDfq5YG3raxU4SuoJrSrJY3GwsC+1t7aJRM2ZBV2SPN8SANUF6N MTGw== X-Gm-Message-State: APjAAAX+sMx1G179XC3zJZco0IAn9l1r5GE4O9fMVNqfJQ3OF5wJd0T6 uVdyhjVRkP71J7SEiZB4WWPOwNfkgdwpEyfq6Vsf7g== X-Google-Smtp-Source: APXvYqzjeuR0QoI74Bg4FY4rDK7iO94U8jxxM+4ZmwcnBeXq3O1wzv2M7/eBlqXtpUp+/eDJDO885/hDHlWnIVspn7o= X-Received: by 2002:adf:ec42:: with SMTP id w2mr9900629wrn.32.1574339997274; Thu, 21 Nov 2019 04:39:57 -0800 (PST) MIME-Version: 1.0 References: <20190823105539.13260-1-sami.mujawar@arm.com> <20190823105539.13260-19-sami.mujawar@arm.com> <20191121123542.GD7359@bivouac.eciton.net> In-Reply-To: <20191121123542.GD7359@bivouac.eciton.net> From: "Ard Biesheuvel" Date: Thu, 21 Nov 2019 13:39:55 +0100 Message-ID: Subject: Re: [PATCH v1 18/19] ArmPlatformPkg: Fix comparison of constants warning To: Leif Lindholm Cc: Sami Mujawar , edk2-devel-groups-io , Alexei Fedorov , Matteo Carlini , nd Content-Type: text/plain; charset="UTF-8" On Thu, 21 Nov 2019 at 13:35, Leif Lindholm wrote: > > On Fri, Aug 23, 2019 at 11:55:38 +0100, 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. > > > > Fix this warning by enclosing the code in appropriate > > #if .. #else .. #endif directives. > > > > Signed-off-by: Sami Mujawar > > Reviewed-by: Leif Lindholm > I don't like this at all. If two expressions happen to evaluate to the same constant, we should be able to compare them using C code. I think we should disable the warning instead. > > --- > > ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c > > index 2d3c279cce49304959953ec4a34b50e09a7d0045..dabf099b9bc82e1fb1bd5a2eae3fa4b5878a9e07 100644 > > --- a/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c > > +++ b/ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.c > > @@ -174,10 +174,10 @@ PL011UartInitializePort ( > > // > > > > // If PL011 Integer value has been defined then always ignore the BAUD rate > > - if (FixedPcdGet32 (PL011UartInteger) != 0) { > > +#if (FixedPcdGet32 (PL011UartInteger) != 0) > > Integer = FixedPcdGet32 (PL011UartInteger); > > Fractional = FixedPcdGet32 (PL011UartFractional); > > - } else { > > +#else > > // If BAUD rate is zero then replace it with the system default value > > if (*BaudRate == 0) { > > *BaudRate = FixedPcdGet32 (PcdSerialBaudRate); > > @@ -197,7 +197,7 @@ PL011UartInitializePort ( > > Divisor = (UINT32)DivisorValue; > > Integer = Divisor >> FRACTION_PART_SIZE_IN_BITS; > > Fractional = Divisor & FRACTION_PART_MASK; > > - } > > +#endif > > > > // > > // If PL011 is already initialized, check the current settings > > -- > > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' > > > >