https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64798

--- Comment #8 from rguenther at suse dot de <rguenther at suse dot de> ---
On Tue, 27 Jan 2015, jakub at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64798
> 
> Jakub Jelinek <jakub at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |jakub at gcc dot gnu.org
> 
> --- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> __BIGGEST_ALIGNMENT__ is unnecessarily large, e.g. on i?86-linux, it is 16,
> while you only need to guarantee 8-byte alignment.
> Isn't the bug just in the badalloc1.C testcase, if it provides its own malloc,
> it should IMHO guarantee the system malloc alignments (generally, something
> like alignment of
> union U
> {
>   long long ll;
>   double d;
>   long double ld;
>   void *p;
> };
> .

no, badalloc1.C provides __BIGGEST_ALIGNMENT__ aligned memory.  The bug
is in the EH allocator which allocates the extra size_t entry aligned
but the EH object itself only size_t aligned.  It's documented
that __attribute__((aligned)) aligns to the biggest type so using
__BIGGEST_ALIGNMENT__ looks correct here - this is also what malloc ()
guarantees for alignment, no?  Do we have any other means of getting
the same alignment as malloc () provides?

Btw, it still wastes a lot less space than the previous allocator.

Bug in the patch anyway and the following hunk is also needed:

@@ -185,7 +186,7 @@ namespace
     {
       __gnu_cxx::__scoped_lock sentry(emergency_mutex);
       allocated_entry *e = reinterpret_cast <allocated_entry *>
-       (reinterpret_cast <char *> (data) - sizeof (std::size_t));
+       (reinterpret_cast <char *> (data) - offsetof (allocated_entry, 
data));
       std::size_t sz = e->size;
       if (!first_free_entry)
        {

Reply via email to