[PUSHED] Fix off-by-one storage problem in irange_allocator.

Jakub Jelinek jakub@redhat.com
Tue Oct 6 12:55:33 GMT 2020


On Tue, Oct 06, 2020 at 08:47:53AM -0400, Andrew MacLeod wrote:
> > I think the proper alignment will be guaranteed if irange and tree[] are
> > obstack_alloc'd separately.  They don't need to be adjacent, do they?
> > 
> > 
> They do not, it just seemed wasteful to do 2 allocs each time, and it'd be
> nice to have them co-located since accessing one inevitable leads to
> accessing the other.

When using normal allocator like malloc or ggc allocation I'd totally agree
here, but I actually think with obstack it is better to do two successive
allocations.
obstack_alloc is generally pretty cheap, in the common case there is room
for the allocation and so it just bumps the next pointer in the structure
and that is it, for the two allocation the same like with one.
And, if there is room just for the irange and not for the subsequent
allocation, with two allocations they wouldn't be collocated, but wouldn't
waste the memory that would otherwise remain unused.

	Jakub



More information about the Gcc-patches mailing list