From: Richard Biener <richard.guenther@gmail.com>
To: Krister Walfridsson <krister.walfridsson@gmail.com>
Cc: Andrew MacLeod <amacleod@redhat.com>, GCC Development <gcc@gcc.gnu.org>
Subject: Re: GIMPLE undefined behavior
Date: Fri, 2 Sep 2022 08:19:47 +0200 [thread overview]
Message-ID: <CAFiYyc0o7yEDZU2TuNmLiQ1OhCpN+Ncu8ZYU49uQWBNCunpeTw@mail.gmail.com> (raw)
In-Reply-To: <Pine.NEB.4.64.2209012353020.21481@gateway.kwa>
On Fri, Sep 2, 2022 at 2:03 AM Krister Walfridsson
<krister.walfridsson@gmail.com> wrote:
>
> On Thu, 1 Sep 2022, Richard Biener wrote:
>
> > It's generally poorly documented what is considered 'undefined behavior'.
> > We desparately need a section in the internals manual for this.
> > For the {L,R}SHIFT_EXPR case we assume the shift operand is
> > in range of [0, precision - 1], so in theory value-range propagation could
> > infer that b_8(D) < 32 after it "executed". But it seems that
> > range-on-exit doesn't do that yet.
> [...]
> > The problem with shifts is that there's not a "do it anway, but without
> > undefined behavior" operation to substitute.
>
> I read this as I should not report these as bugs for now. But I'll
> probably keep this as UB in my tool to get an idea of how often this
> happens...
Can you report a single case as kind-of meta-bug for this particular issue?
That would be nice.
>
> >> Calling f(-3, 0x75181005) makes slsr_9 overflow in the optimized code,
> >> even though the original did not overflow. My understanding is that signed
> >> overflow invokes undefined behavior in GIMPLE, so this is a bug in
> >> ifcombine. Is my understanding correct?
> >
> > Yes, the above would be a bug - again value-range propagation might be
> > leveraged to produce a wrong-code testcase.
>
> OK. I'll open bugs for the signed overflow issues the tool finds.
Thanks.
> >> I would appreciate some comments on which non-memory-related operations I
> >> should treat as invoking undefined behavior (memory operations are more
> >> complicated, and I'll be back with more concrete questions later...).
> >
> > The more "interesting" cases are uninitialized values (registers or memory).
>
> Yes, this is the next thing I was planning to implement. :)
>
>
> > In general what we should worry about most is introducing undefined
> > behavior that, when a later pass can assume it doesn't happen, causes
> > wrong code to be generated. Likewise when we have late instrumentation
> > that would flag such undefined behavior as a user error.
>
> Agreed. But that comes back to the issue of lacking documentation... :(
Yes. There's some "unknowns" in what GIMPLE treats as undefined given
the lack of a strict specification but there's also implementation facts for
which cases optimization passes already exploit undefined behavior (but even
that subset is not documented).
Richard.
> /Krister
prev parent reply other threads:[~2022-09-02 6:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 23:55 Krister Walfridsson
2022-09-01 6:54 ` Richard Biener
2022-09-02 0:03 ` Krister Walfridsson
2022-09-02 6:19 ` Richard Biener [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-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=CAFiYyc0o7yEDZU2TuNmLiQ1OhCpN+Ncu8ZYU49uQWBNCunpeTw@mail.gmail.com \
--to=richard.guenther@gmail.com \
--cc=amacleod@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=krister.walfridsson@gmail.com \
/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).