From: Adrian Moreno <amorenoz@redhat.com>
To: Xi Ruoyao <xry111@mengyan1223.wang>,
Florian Weimer <fweimer@redhat.com>,
Adrian Moreno via Gcc-help <gcc-help@gcc.gnu.org>
Cc: David Brown <david.brown@hesbynett.no>
Subject: Re: broken code only when optimized "-O2"
Date: Wed, 22 Dec 2021 17:05:09 +0100 [thread overview]
Message-ID: <c2f374a7-991d-2724-8cf4-1eba9da843e0@redhat.com> (raw)
In-Reply-To: <9eb235680e05e02f8ac6589a52d1996b3cfc0bb5.camel@mengyan1223.wang>
On 12/22/21 11:36, Xi Ruoyao wrote:
> On Wed, 2021-12-22 at 11:34 +0100, Adrian Moreno via Gcc-help wrote:
>>
>>
>> On 12/22/21 11:27, Florian Weimer wrote:
>>> * Adrian Moreno via Gcc-help:
>>>
>>>> So here I do not know what the compiler would think about "pos" if
>>>> it
>>>> happens to point to some invalid stack address.
>>>
>>> In such cases, the compiler typically assumes that the code in
>>> question
>>> is never executed. This means that the comparison does not need to
>>> be
>>> performed, among other things.
>>>
>>
>> So it wouldn't cause undefined behavior?
>
> It *is* undefined behavior, and the compiler can remove any execution
> paths which will eventually hit an undefined behavior.
>
Thanks for confirming.
--
Adrián Moreno
next prev parent reply other threads:[~2021-12-22 16:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-21 15:40 Adrian Moreno
2021-12-21 16:05 ` Stefan Ring
2021-12-21 16:13 ` Adrian Moreno
2021-12-21 16:39 ` Segher Boessenkool
2021-12-21 17:05 ` David Brown
2021-12-22 9:24 ` Adrian Moreno
2021-12-22 10:27 ` Florian Weimer
2021-12-22 10:34 ` Adrian Moreno
2021-12-22 10:36 ` Xi Ruoyao
2021-12-22 16:05 ` Adrian Moreno [this message]
2021-12-22 15:32 ` LIU Hao
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-all 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=c2f374a7-991d-2724-8cf4-1eba9da843e0@redhat.com \
--to=amorenoz@redhat.com \
--cc=david.brown@hesbynett.no \
--cc=fweimer@redhat.com \
--cc=gcc-help@gcc.gnu.org \
--cc=xry111@mengyan1223.wang \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).