public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Richard Biener <rguenther@suse.de>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Avoid default-initializing auto_vec<T, N> storage
Date: Fri, 24 Feb 2023 11:02:07 +0100	[thread overview]
Message-ID: <Y/iLH/nkGqPuLjnz@tucnak> (raw)
In-Reply-To: <CACb0b4n3VcQac1g7u39SzQNQvfovMkbaMV4jicpotPVKvFT+kw@mail.gmail.com>

On Fri, Feb 24, 2023 at 09:55:13AM +0000, Jonathan Wakely wrote:
> > You would still be accessing past the end of the
> > vec<vl_embed>::m_vecdata array which is UB.
> 
> My thinking is something like:
> 
> // New tag type
> struct vl_relative { };
> 
> // This must only be used as a member subobject of another type
> // which provides the trailing storage.
> template<typename T>
> struct vec<T, va_heap, vl_relative>
> {
>   T *address (void) { return (T*)(m_vecpfx+1); }
>   const T *address (void) const { return (T*)(m_vecpfx+1); }
> 
>   alignas(T) alignas(vec_prefix) vec_prefix m_vecpfx;
> };
> 
> template<typename T, size_t N /* = 0 */>
> class auto_vec : public vec<T, va_heap>
> {
>   // ...
> private:
>   vec<T, va_heap, vl_relative> m_head;
>   T m_data[N];
> 
> static_assert(...);
> };

Maybe this would work, vl_relative even could be vl_embed.
Because vl_embed I believe is used in two spots, part of
auto_vec where it is followed by m_data and on heap or GGC
allocated memory where vec<..., vl_embed> is followed by
further storage for the vector.

	Jakub


  reply	other threads:[~2023-02-24 10:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 12:54 Richard Biener
2023-02-23 13:56 ` Jakub Jelinek
2023-02-23 15:02   ` Richard Biener
2023-02-23 15:20     ` Jakub Jelinek
2023-02-24  9:02       ` Richard Biener
2023-02-24  9:34         ` Richard Biener
2023-02-24  9:48           ` Jakub Jelinek
2023-02-24  9:50             ` Jonathan Wakely
2023-02-24  9:55               ` Jakub Jelinek
2023-02-24  9:55               ` Jonathan Wakely
2023-02-24 10:02                 ` Jakub Jelinek [this message]
2023-02-24 10:24                   ` Jakub Jelinek
2023-02-24 10:30                     ` Jonathan Wakely
2023-02-24 10:59                       ` Jakub Jelinek
2023-02-24 11:04                         ` Jakub Jelinek

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=Y/iLH/nkGqPuLjnz@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely@redhat.com \
    --cc=rguenther@suse.de \
    /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).