Re: [libstdc++] Improve M_check_len

2023-06-20 Thread Jonathan Wakely via Gcc-patches
On Tue, 20 Jun 2023 at 11:45, Jonathan Wakely wrote: > On Tue, 20 Jun 2023 at 09:21, Andreas Schwab wrote: > >> On Jun 20 2023, Jakub Jelinek via Gcc-patches wrote: >> >> > Is it safe even on 64bit targets? I mean, doesn't say PowerPC already >> allow >> > full 64-bit virtual address space? The

Re: [libstdc++] Improve M_check_len

2023-06-20 Thread Jonathan Wakely via Gcc-patches
On Tue, 20 Jun 2023 at 09:21, Andreas Schwab wrote: > On Jun 20 2023, Jakub Jelinek via Gcc-patches wrote: > > > Is it safe even on 64bit targets? I mean, doesn't say PowerPC already > allow > > full 64-bit virtual address space? The assumption that one can't have > > more than half of virtual a

Re: [libstdc++] Improve M_check_len

2023-06-20 Thread Andreas Schwab via Gcc-patches
On Jun 20 2023, Jakub Jelinek via Gcc-patches wrote: > Is it safe even on 64bit targets? I mean, doesn't say PowerPC already allow > full 64-bit virtual address space? The assumption that one can't have > more than half of virtual address space allocations is true right now at > least on x86-64,

Re: [libstdc++] Improve M_check_len

2023-06-20 Thread Jakub Jelinek via Gcc-patches
On Tue, Jun 20, 2023 at 09:50:25AM +0200, Jan Hubicka wrote: > > > > > > size_type > > > _M_check_len(size_type __n, const char* __s) const > > > { > > > const size_type __size = size(); > > > const size_type __max_size = max_size(); > > > > > > if (__is_sa

Re: [libstdc++] Improve M_check_len

2023-06-20 Thread Jan Hubicka via Gcc-patches
> > > > > > size_type > > > _M_check_len(size_type __n, const char* __s) const > > > { > > > const size_type __size = size(); > > > const size_type __max_size = max_size(); > > > > > > if (__is_same(allocator_type, allocator<_Tp>) > > > && __s

Re: [libstdc++] Improve M_check_len

2023-06-20 Thread Jan Hubicka via Gcc-patches
> > > > size_type > > _M_check_len(size_type __n, const char* __s) const > > { > > const size_type __size = size(); > > const size_type __max_size = max_size(); > > > > if (__is_same(allocator_type, allocator<_Tp>) > > && __size > __max_size /

Re: [libstdc++] Improve M_check_len

2023-06-19 Thread Jan Hubicka via Gcc-patches
> On Mon, 19 Jun 2023 at 12:20, Jakub Jelinek wrote: > > > On Mon, Jun 19, 2023 at 01:05:36PM +0200, Jan Hubicka via Gcc-patches > > wrote: > > > - if (max_size() - size() < __n) > > > - __throw_length_error(__N(__s)); > > > + const size_type __max_size = max_size(); > > > + // O

Re: [libstdc++] Improve M_check_len

2023-06-19 Thread Jonathan Wakely via Gcc-patches
On Mon, 19 Jun 2023 at 16:13, Jonathan Wakely wrote: > On Mon, 19 Jun 2023 at 12:20, Jakub Jelinek wrote: > >> On Mon, Jun 19, 2023 at 01:05:36PM +0200, Jan Hubicka via Gcc-patches >> wrote: >> > - if (max_size() - size() < __n) >> > - __throw_length_error(__N(__s)); >> > + const si

Re: [libstdc++] Improve M_check_len

2023-06-19 Thread Jonathan Wakely via Gcc-patches
P.S. please CC libstd...@gcc.gnu.org for all libstdc++ patches. On Mon, 19 Jun 2023 at 16:13, Jonathan Wakely wrote: > On Mon, 19 Jun 2023 at 12:20, Jakub Jelinek wrote: > >> On Mon, Jun 19, 2023 at 01:05:36PM +0200, Jan Hubicka via Gcc-patches >> wrote: >> > - if (max_size() - size() < __n)

Re: [libstdc++] Improve M_check_len

2023-06-19 Thread Jonathan Wakely via Gcc-patches
On Mon, 19 Jun 2023 at 12:20, Jakub Jelinek wrote: > On Mon, Jun 19, 2023 at 01:05:36PM +0200, Jan Hubicka via Gcc-patches > wrote: > > - if (max_size() - size() < __n) > > - __throw_length_error(__N(__s)); > > + const size_type __max_size = max_size(); > > + // On 64bit systems

Re: [libstdc++] Improve M_check_len

2023-06-19 Thread Jakub Jelinek via Gcc-patches
On Mon, Jun 19, 2023 at 01:05:36PM +0200, Jan Hubicka via Gcc-patches wrote: > - if (max_size() - size() < __n) > - __throw_length_error(__N(__s)); > + const size_type __max_size = max_size(); > + // On 64bit systems vectors can not reach overflow by growing > + // by small si

Re: [libstdc++] Improve M_check_len

2023-06-19 Thread Jan Hubicka via Gcc-patches
> > - if (max_size() - size() < __n) > > - __throw_length_error(__N(__s)); > > + // On 64bit systems vectors of small sizes can not > > + // reach overflow by growing by small sizes; before > > + // this happens, we will run out of memory. > > + if (__builtin_c

Re: [libstdc++] Improve M_check_len

2023-06-19 Thread Jonathan Wakely via Gcc-patches
On Sun, 18 Jun 2023 at 19:37, Jan Hubicka wrote: > Hi, > _M_check_len is used in vector reallocations. It computes __n + __s but > does > checking for case that (__n + __s) * sizeof (Tp) would overflow ptrdiff_t. > Since we know that __s is a size of already allocated memory block if __n > is > n

[libstdc++] Improve M_check_len

2023-06-18 Thread Jan Hubicka via Gcc-patches
Hi, _M_check_len is used in vector reallocations. It computes __n + __s but does checking for case that (__n + __s) * sizeof (Tp) would overflow ptrdiff_t. Since we know that __s is a size of already allocated memory block if __n is not too large, this will never happen on 64bit systems since memor