From: Laszlo Ersek <lersek@redhat.com>
To: "Marvin Häuser" <Marvin.Haeuser@outlook.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "ruiyu.ni@intel.com" <ruiyu.ni@intel.com>,
"eric.dong@intel.com" <eric.dong@intel.com>,
"star.zeng@intel.com" <star.zeng@intel.com>
Subject: Re: [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550: Prevent truncating constant values.
Date: Wed, 28 Feb 2018 12:14:50 +0100 [thread overview]
Message-ID: <d97d8b14-c91f-e889-877c-06fe56dea8b1@redhat.com> (raw)
In-Reply-To: <AM4PR06MB14910A8BDFAEB35D3CA0AE4080C00@AM4PR06MB1491.eurprd06.prod.outlook.com>
On 02/27/18 19:55, Marvin Häuser wrote:
> Hey Laszlo,
>
> Thanks for your... detailed explanation. :)
> I actually submitted another patch to prevent what you explained -
> "[edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise operations.",
> which marks all BIT defines (and more) as unsigned.
> Most definitely I should have mentioned it in the commit message or
> held it back till that patch will be accepted (or denied?), seems like
> I forgot about that.
> Would you still prefer your suggestion even when the Base.h patch is
> merged? After all, int might happen to be even larger than INT32, if
> I'm not mistaken.
>
> I'm quite sure VS2015x86 issued the warning despite that commit being
> applied locally. It seems to always warn when a constant is truncated,
> explicitely or implicitely, to give you the change to increase its
> size:
> https://msdn.microsoft.com/en-us/library/sz5z1byt.aspx
With the other (pre-requisite) change applied, such that
#define BIT0 0x00000001u
#define BIT1 0x00000002u
it's even less comprehensible why VS2015x86 warns about the original
code, namely:
(UINT16)~(BIT0 | BIT1)
In this case we apply bit-or to two "unsigned int" operands, and then
apply bit-neg to the "unsigned int" result. Finally we explicitly cast
the expression to another unsigned integer type. All well-defined.
The MSDN reference writes, "The type conversion causes a constant to
exceed the space allocated for it." I don't understand how that does
*not* apply to the post-patch code, namely
(UINT16)~(UINT16)(BIT0 | BIT1)
Again, in this variant (with the BIT macros being unsigned), we
basically have
(UINT16)(-4)
How on earth does the constant "minus 4" (-4) fit in the UINT16 "space"?
It totally doesn't.
Sorry, VS2015x86 boggles my mind. I think it's a compiler bug, plain and
simple. Please just do whatever you have to do to shut it up. I give up.
Thanks,
Laszlo
prev parent reply other threads:[~2018-02-28 11:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20180227164940.6956-1-Marvin.Haeuser@outlook.com>
2018-02-27 16:49 ` [PATCH 2/2] MdeModulePkg/BaseSerialPortLib16550: Prevent truncating constant values Marvin Häuser
2018-02-27 18:35 ` Laszlo Ersek
2018-02-27 18:55 ` Marvin Häuser
2018-02-28 2:44 ` Zeng, Star
2018-03-01 17:34 ` Marvin Häuser
2018-03-02 2:01 ` Zeng, Star
2018-02-28 11:14 ` Laszlo Ersek [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d97d8b14-c91f-e889-877c-06fe56dea8b1@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox