public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Paul Floyd <paulf@free.fr>
Cc: "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: Safe transposition of logical and operands
Date: Mon, 18 Sep 2023 08:23:14 +0100	[thread overview]
Message-ID: <CAH6eHdQ69AomJUEcwDP9K_=TvFe9wRgaRU9NZMXOmgU1AWQVwQ@mail.gmail.com> (raw)
In-Reply-To: <c1887f72-d532-1cc1-f71c-9fdd4f4ed056@free.fr>

[-- Attachment #1: Type: text/plain, Size: 1485 bytes --]

On Mon, 18 Sept 2023, 08:03 Paul Floyd via Gcc, <gcc@gcc.gnu.org> wrote:

>
>
> On 17-09-23 22:51, Jonathan Wakely wrote:
>
> >
> > Why would it be trapping? It's loading an int64_t, which might be
> > uninitialised but it can't trap.
>
> In this context I think that Valgrind is considering that any memory
> load could trap.
>

There are no padding bits in int64_t and all object representations are
valid values, so it has no trap representations.



> > *f on a std::optional is not like dereferencing a pointer, the int64_t
> > memory location is always present as part of the object.
>
> For this
>
> movq    40(%rbx), %rax
>
> unless you know that what RBX+40 is pointing to is safe to dereference
> it's not different to dereferencing a pointer.
>

If it isn't safe to load that integer then it isn't safe to call f.operator
bool() either. GCC knows they are part of the same object.


> So I think that the problem is that Valgrind is being cautious and not
> allowing any loads but GCC is accepting what it considers safe loads
> from the stack.
>

Yes, GCC assumes that the reference is bound to a valid object, because C++
requires that to be true. Of course memcheck can't assume that, because one
of its main reasons to exist is to find undefined behaviour where that
isn't true!

I think what GCC is doing is a valid transformation, in the context of a
valid C++ program. But I'm not sure that helps valgrind, which doesn't have
the liberty of assuming a valid program.

  reply	other threads:[~2023-09-18  7:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-17 19:33 Paul Floyd
2023-09-17 20:51 ` Jonathan Wakely
2023-09-18  7:03   ` Paul Floyd
2023-09-18  7:23     ` Jonathan Wakely [this message]
2023-09-18  8:00       ` Richard Biener
2023-09-18 14:46         ` Floyd, Paul
2023-09-18 14:55           ` Richard Biener
2023-09-18 17:56             ` Paul Floyd
2023-09-18 19:09               ` Martin Uecker
2023-09-18 20:15                 ` Paul Floyd
2023-09-18 20:52                   ` Martin Uecker
2023-09-19  5:03                     ` Paul Floyd
2023-09-18  9:36       ` Jonathan Wakely
2023-09-18 10:30 ` Andreas Schwab

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='CAH6eHdQ69AomJUEcwDP9K_=TvFe9wRgaRU9NZMXOmgU1AWQVwQ@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=paulf@free.fr \
    /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).