This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC turns &~ into | due to undefined bit-shift without warning
- From: Allan Sandfeld Jensen <linux at carewolf dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 22 Mar 2019 10:27:38 +0100
- Subject: Re: GCC turns &~ into | due to undefined bit-shift without warning
- References: <4af9e251-f4c3-a5a4-e33d-fb8750c87e36@redheads.de> <2662071.e9J7NaK4W3@twilight> <20190321223148.GD7611@tucnak>
On Donnerstag, 21. März 2019 23:31:48 CET Jakub Jelinek wrote:
> On Thu, Mar 21, 2019 at 11:19:54PM +0100, Allan Sandfeld Jensen wrote:
> > Hmm, I am curious. How strongly would gcc assume x is 0?
>
> If x is not 0, then it is undefined behavior and anything can happen,
> so yes, it can assume x is 0, sometimes gcc does that, sometimes not,
> it is not required to do that.
>
> > From having fixed UBSAN warnings, I have seen many cases where undefined
> > behavior was performed, but where the code was aware of it and the final
>
> Any program where it printed something (talking about -fsanitize=undefined,
> not the few sanitizers that go beyond what is required by the language)
> is undefined, period. It can happen to "work" as some users expect, it can
> crash, it can format your disk or anything else. There is no well defined
> after a process runs into UB.
>
That's nonsense and you know it. There are plenty of things that are undefined
by the C standard that we rely on anyway.
But getting back to the question, well GCC carry such information further, and
thus break code that is otherwise correct behaving on all known architectures,
just because the C standard hasn't decided on one of two possible results?
'Allan