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: Jakub Jelinek <jakub at redhat dot com>
- To: Allan Sandfeld Jensen <linux at carewolf dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 21 Mar 2019 23:31:48 +0100
- Subject: Re: GCC turns &~ into | due to undefined bit-shift without warning
- References: <4af9e251-f4c3-a5a4-e33d-fb8750c87e36@redheads.de> <20190311091449.GB7611@tucnak> <2662071.e9J7NaK4W3@twilight>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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.
Jakub