From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4286C2034D8E8 for ; Wed, 28 Feb 2018 03:35:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D84C6402291E; Wed, 28 Feb 2018 11:42:05 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-11.rdu2.redhat.com [10.10.120.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id D50E62026E04; Wed, 28 Feb 2018 11:42:04 +0000 (UTC) To: Andrew Fish Cc: =?UTF-8?Q?Marvin_H=c3=a4user?= , "edk2-devel@lists.01.org" , "ruiyu.ni@intel.com" , "eric.dong@intel.com" , "star.zeng@intel.com" References: <657bb4e2-7271-6a24-7cd3-aecdaaa005f5@redhat.com> <6C7D5245-F76E-4FF1-B7B5-B1254EA83C44@apple.com> From: Laszlo Ersek Message-ID: <20348a44-8b73-3389-59a4-3b67cd35e01c@redhat.com> Date: Wed, 28 Feb 2018 12:42:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <6C7D5245-F76E-4FF1-B7B5-B1254EA83C44@apple.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Feb 2018 11:42:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Feb 2018 11:42:05 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: Re: [PATCH 1/2] MdeModulePkg/PciBusDxe: Prevent truncating constant values. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Feb 2018 11:35:59 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 02/27/18 19:50, Andrew Fish wrote: > > >> On Feb 27, 2018, at 10:42 AM, Laszlo Ersek wrote: >> >> On 02/27/18 17:49, Marvin Häuser wrote: >>> The toolcahin VS2015x86 issues warnings when truncating constant >>> values. Explicitely cast such to avoid it. >>> >>> Contributed-under: TianoCore Contribution Agreement 1.1 >>> Signed-off-by: Marvin Haeuser >>> --- >>> MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c >>> index 2f713fcee95e..a752853f3e9e 100644 >>> --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c >>> +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c >>> @@ -1936,7 +1936,7 @@ ProgramP2C ( >>> &BridgeControl >>> ); >>> >>> - BridgeControl &= (UINT16) ~PCI_CARD_PREFETCHABLE_MEMORY_0_ENABLE; >>> + BridgeControl &= (UINT16) ~(UINT16)PCI_CARD_PREFETCHABLE_MEMORY_0_ENABLE; >>> PciIo->Pci.Write ( >>> PciIo, >>> EfiPciIoWidthUint16, >>> @@ -2005,7 +2005,7 @@ ProgramP2C ( >>> &BridgeControl >>> ); >>> >>> - BridgeControl &= (UINT16) ~(PCI_CARD_PREFETCHABLE_MEMORY_1_ENABLE); >>> + BridgeControl &= (UINT16) ~(UINT16)(PCI_CARD_PREFETCHABLE_MEMORY_1_ENABLE); >>> PciIo->Pci.Write ( >>> PciIo, >>> EfiPciIoWidthUint16, >>> >> >> My recommendation is the same as for: >> >> [edk2] [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550: Prevent >> truncating constant values. >> >> #define PCI_CARD_PREFETCHABLE_MEMORY_0_ENABLE BIT8 >> #define PCI_CARD_PREFETCHABLE_MEMORY_1_ENABLE BIT9 >> >> #define BIT8 0x00000100 >> #define BIT9 0x00000200 >> > > Laszlo, > > Stupid question? Would making BIT8 0x00000100U help? I notice we use ULL for the larger ones, and I don't remember why we don't use U for the ones that fit into a int? I don't know why BIT[0..31] don't use the U suffix from the beginning. I agree they should have. Adding the suffixes now is the right thing in theory, although some "clever" applications of those macros could regress as a result. Regarding the question whether this patch would be obviated by making BIT[0..31] unsigned, Marvin explained elsewhere that just making BIT[0..31] unsigned didn't help with suppressing the warning. As I commented under Marvin's explanation, I understand neither why the compiler warns about the current code (with or without making BIT[0..31] unsigned), nor -- assuming the original warning is somehow justifiable -- why the warning is apparently silenced by inserting a UINT16 cast ahead of the bit-neg. As far as I could see, if the warning applied to the original code, it should have applied to the patched code too. Thanks Laszlo