public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Ville Voutilainen <ville.voutilainen@gmail.com>
Cc: Marc Glisse <marc.glisse@inria.fr>,
	"libstdc++" <libstdc++@gcc.gnu.org>,
	 gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: std::optional defaut constructor
Date: Thu, 4 Jun 2020 13:41:36 +0200	[thread overview]
Message-ID: <CAFiYyc2Vy9NUODk-Ob1TVjfTQFJb3=Ez1MgWZFa3CGZ97DhuXw@mail.gmail.com> (raw)
In-Reply-To: <CAFk2RUbGcPDtEKwMEjLxiLde8_zjxDQWyUEidaOAr90y_enRRA@mail.gmail.com>

On Thu, Jun 4, 2020 at 11:34 AM Ville Voutilainen via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Thu, 4 Jun 2020 at 11:53, Marc Glisse <marc.glisse@inria.fr> wrote:
> >
> > On Thu, 4 Jun 2020, Ville Voutilainen wrote:
> >
> > > On Thu, 4 Jun 2020 at 11:00, Marc Glisse <marc.glisse@inria.fr> wrote:
> > >> Maybe create a buffer, fill it with some non-zero values (-1?), then call
> > >> placement new, and read some value in the middle of the buffer, possibly
> > >> with some protection against optimizations? Ah, no, actual constructors
> > >> are fine, it is only the inlined initialization that happens with the
> > >> defaulted constructor that zeroes things.
> > >
> > > The zero-init is part of value-initialization of a class type with a
> > > defaulted default constructor, so value-initialization with placement
> > > new should indeed show us whether the target buffer is zeroed.
> >
> > Ah, yes, I had forgotten the empty () at the end of the operator new line
> > when testing. Now the patch makes this runtime test go from abort to
> > success at -O0 (with optimizations, the memset is removed as dead code). I
> > am still not sure we want this kind of test though. And I added launder
> > more to quiet a warning than with confidence that it does the right thing.
> >
> > #include <optional>
> > struct A {
> >    int a[1024];
> > };
> > typedef std::optional<A> O;
> > int main(){
> >    unsigned char t[sizeof(O)];
> >    __builtin_memset(t, -1, sizeof(t));
> >    new(t)O();
> >    if(std::launder(t)[512] != (unsigned char)(-1)) __builtin_abort();
> > }
>
> Yeah, I think the patch is OK with or without the test. As a side
> note, you don't need the launder
> if the check uses the pointer value returned by placement-new.

Doesn't the placement new make the memory state of anything
not explicitely initialized indeterminate?  That is, isn't the
testcase broken anyways since GCC can elide the memset
when seeing the placement new?

Thanks,
Richard.

  reply	other threads:[~2020-06-04 11:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 22:50 Marc Glisse
2020-06-03 23:05 ` Ville Voutilainen
2020-06-03 23:12   ` Marc Glisse
2020-06-03 23:20     ` Ville Voutilainen
2020-06-04  0:05       ` Ville Voutilainen
2020-06-04  0:10         ` Ville Voutilainen
2020-06-04  7:21           ` Marc Glisse
2020-06-04  7:34             ` Ville Voutilainen
2020-06-04  8:00               ` Marc Glisse
2020-06-04  8:25                 ` Ville Voutilainen
2020-06-04  8:53                   ` Marc Glisse
2020-06-04  9:20                     ` Ville Voutilainen
2020-06-04 11:41                       ` Richard Biener [this message]
2020-06-04 11:43                         ` Ville Voutilainen
2020-06-04 11:46                         ` Marc Glisse
2020-06-04 13:38                         ` Jonathan Wakely
2020-06-04 11:44                       ` Marc Glisse
2020-06-04 13:41               ` Jonathan Wakely
2020-06-04 13:46 ` Jonathan Wakely
2020-06-19 11:50   ` Jonathan Wakely

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='CAFiYyc2Vy9NUODk-Ob1TVjfTQFJb3=Ez1MgWZFa3CGZ97DhuXw@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=marc.glisse@inria.fr \
    --cc=ville.voutilainen@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).