public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Andrew Pinski <pinskia@gmail.com>,
	Gavin Ray <ray.gavin97@gmail.com>,
	 "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: Bug with GCC's handling of lifetimes of implicit-lifetime types
Date: Sun, 11 Dec 2022 12:02:24 +0000	[thread overview]
Message-ID: <CAH6eHdRTzStG-CjP9aGjLfYzObvO2T_3J3AcXet7L-Pcmh=wzQ@mail.gmail.com> (raw)
In-Reply-To: <CAFiYyc3_viYHoBtmsjpDBnU+JRYRmzguPp3spxfwbeS_97e2Cw@mail.gmail.com>

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

On Sun, 11 Dec 2022, 09:12 Richard Biener, <richard.guenther@gmail.com>
wrote:

> On Sat, Dec 10, 2022 at 7:45 PM Andrew Pinski via Gcc <gcc@gcc.gnu.org>
> wrote:
> >
> > On Sat, Dec 10, 2022 at 10:36 AM Jonathan Wakely via Gcc
> > <gcc@gcc.gnu.org> wrote:
> > >
> > > On Sat, 10 Dec 2022 at 17:42, Gavin Ray via Gcc <gcc@gcc.gnu.org>
> wrote:
> > > >
> > > > This came up when I was asking around about what the proper way was
> to:
> > > >
> > > > - Allocate aligned storage for a buffer pool/page cache
> > > > - Then create pointers to "Page" structs inside of the storage
> memory area
> > > >
> > > > I thought something like this might do:
> > > >
> > > > struct buffer_pool
> > > > {
> > > >   alignas(PAGE_SIZE) std::byte storage[NUM_PAGES * PAGE_SIZE];
> > > >   page* pages = new (storage) page[NUM_PAGES];
> > > > }
> > > >
> > > > Someone told me that this was a valid solution but not to do it,
> because it
> > > > wouldn't function properly on GCC
> > > > They gave this as a reproduction:
> > > >
> > > > https://godbolt.org/z/EhzM37Gzh
> > > >
> > > > I'm not experienced enough with C++ to grok the connection between
> this
> > > > repro and my code,
> > >
> > > Me neither. I don't think there is any connection, because I don't
> > > think the repro shows what they think it shows.
> > >
> > > > but I figured
> > > > I'd post it on the mailing list in case it was useful for
> others/might get
> > > > fixed in the future =)
> > > >
> > > > They said it had to do with "handling of lifetimes of
> implicit-lifetime
> > > > types"
> > >
> > > I don't think that code is a valid implementation of
> > > start_lifetime_as. Without a proper implementation of
> > > start_lifetime_as (which GCC doesn't provide yet), GCC does not allow
> > > you to read the bytes of a float as an int, and doesn't give you the
> > > bytes of 1.0f, it gives you 0.
> > >
> > > https://godbolt.org/z/dvncY9Pea works for GCC. But this has nothing to
> > > do your code above, as far as I can see.
> >
> > See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107115#c10 for what
> > is going wrong.
> > Basically GCC does not have a way to express this in the IR currently
> > and there are proposals there on how to do it.
>
> I wouldn't call them "proposals" - basically the C++ language providing
> holes into the TBAA system is a misdesign, it will be incredibly difficult
> to implement this "hole" without sacrifying optimization which means
> people will complain endlessly why std::start_lifetime_as isn't a way
> to circumvent TBAA without losing optimization.
>

People already make holes in the type system, this just lets them do it
without UB. If it's not as fast as their UB, that's ok IMHO.

>

But I don't see what start_lifetime_as has to do with the original problem
anyway. The placement new expression will start lifetimes:

page* pages = new (storage) page[NUM_PAGES];

There's no need to mess with the type system here.

  reply	other threads:[~2022-12-11 12:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-10 17:41 Gavin Ray
2022-12-10 18:35 ` Jonathan Wakely
2022-12-10 18:43   ` Andrew Pinski
2022-12-10 21:48     ` Gavin Ray
2022-12-11  9:11     ` Richard Biener
2022-12-11 12:02       ` Jonathan Wakely [this message]
2022-12-11 13:31         ` Richard Biener
2022-12-11 13:38           ` Gavin Ray
2022-12-11 13:44             ` Gavin Ray
2022-12-12 11:56               ` 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='CAH6eHdRTzStG-CjP9aGjLfYzObvO2T_3J3AcXet7L-Pcmh=wzQ@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=pinskia@gmail.com \
    --cc=ray.gavin97@gmail.com \
    --cc=richard.guenther@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).