Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Jakub Jelinek via Gcc-patches
On Fri, Feb 24, 2023 at 11:59:53AM +0100, Jakub Jelinek via Gcc-patches wrote: > > This needs to be alignas(T) unsigned char m_data[sizeof(T) * N]; > > unsigned char m_data[MAX (N, 2) * sizeof (T)]; > > if we want to preserve current behavior I think. > > I've screwed up, when I was about to c

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Jakub Jelinek via Gcc-patches
On Fri, Feb 24, 2023 at 10:30:00AM +, Jonathan Wakely wrote: > On Fri, 24 Feb 2023 at 10:24, Jakub Jelinek wrote: > > > > On Fri, Feb 24, 2023 at 11:02:07AM +0100, Jakub Jelinek via Gcc-patches > > wrote: > > > Maybe this would work, vl_relative even could be vl_embed. > > > Because vl_embed

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Jonathan Wakely via Gcc-patches
On Fri, 24 Feb 2023 at 10:24, Jakub Jelinek wrote: > > On Fri, Feb 24, 2023 at 11:02:07AM +0100, Jakub Jelinek via Gcc-patches wrote: > > 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_d

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Jakub Jelinek via Gcc-patches
On Fri, Feb 24, 2023 at 11:02:07AM +0100, Jakub Jelinek via Gcc-patches wrote: > 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_em

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Jakub Jelinek via Gcc-patches
On Fri, Feb 24, 2023 at 09:55:13AM +, Jonathan Wakely wrote: > > You would still be accessing past the end of the > > vec::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 anot

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Jonathan Wakely via Gcc-patches
On Fri, 24 Feb 2023 at 09:50, Jonathan Wakely wrote: > > On Fri, 24 Feb 2023 at 09:49, Jakub Jelinek wrote: > > > > Assuming a compiler handles the T m_vecdata[1]; as flexible array member > > like (which we need because standard C++ doesn't have flexible array members > > nor [0] arrays), I wonde

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Jakub Jelinek via Gcc-patches
On Fri, Feb 24, 2023 at 09:50:33AM +, Jonathan Wakely wrote: > On Fri, 24 Feb 2023 at 09:49, Jakub Jelinek wrote: > > > > Assuming a compiler handles the T m_vecdata[1]; as flexible array member > > like (which we need because standard C++ doesn't have flexible array members > > nor [0] arrays)

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Jonathan Wakely via Gcc-patches
On Fri, 24 Feb 2023 at 09:49, Jakub Jelinek wrote: > > Assuming a compiler handles the T m_vecdata[1]; as flexible array member > like (which we need because standard C++ doesn't have flexible array members > nor [0] arrays), I wonder if we instead of the m_auto followed by m_data > trick couldn't

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Jakub Jelinek via Gcc-patches
On Fri, Feb 24, 2023 at 09:34:46AM +, Richard Biener wrote: > > Looking at vec::operator[] which just does > > > > template > > inline const T & > > vec::operator[] (unsigned ix) const > > { > > gcc_checking_assert (ix < m_vecpfx.m_num); > > return m_vecdata[ix]; > > } > > > > the whole

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Richard Biener via Gcc-patches
On Fri, 24 Feb 2023, Richard Biener wrote: > On Thu, 23 Feb 2023, Jakub Jelinek wrote: > > > On Thu, Feb 23, 2023 at 03:02:01PM +, Richard Biener wrote: > > > > > * vec.h (auto_vec): Turn m_data storage into > > > > > uninitialized unsigned char. > > > > > > > > Given that we act

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-24 Thread Richard Biener via Gcc-patches
On Thu, 23 Feb 2023, Jakub Jelinek wrote: > On Thu, Feb 23, 2023 at 03:02:01PM +, Richard Biener wrote: > > > > * vec.h (auto_vec): Turn m_data storage into > > > > uninitialized unsigned char. > > > > > > Given that we actually never reference the m_data array anywhere, > > >

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-23 Thread Jakub Jelinek via Gcc-patches
On Thu, Feb 23, 2023 at 03:02:01PM +, Richard Biener wrote: > > > * vec.h (auto_vec): Turn m_data storage into > > > uninitialized unsigned char. > > > > Given that we actually never reference the m_data array anywhere, > > it is just to reserve space, I think even the alignas(T) there is

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-23 Thread Richard Biener via Gcc-patches
On Thu, 23 Feb 2023, Jakub Jelinek wrote: > On Thu, Feb 23, 2023 at 01:54:27PM +0100, Richard Biener wrote: > > The following avoids default-initializing auto_vec storage for > > non-POD T since that's not what the allocated storage fallback > > will do and it's also not expected for existing case

Re: [PATCH] Avoid default-initializing auto_vec storage

2023-02-23 Thread Jakub Jelinek via Gcc-patches
On Thu, Feb 23, 2023 at 01:54:27PM +0100, Richard Biener wrote: > The following avoids default-initializing auto_vec storage for > non-POD T since that's not what the allocated storage fallback > will do and it's also not expected for existing cases like > > auto_vec, 64> elts; > > which exist

[PATCH] Avoid default-initializing auto_vec storage

2023-02-23 Thread Richard Biener via Gcc-patches
The following avoids default-initializing auto_vec storage for non-POD T since that's not what the allocated storage fallback will do and it's also not expected for existing cases like auto_vec, 64> elts; which exist to optimize the allocation. Bootstrapped and tested on x86_64-unknown-linux-g