From: Richard Biener Date: Wed, 28 Jan 2015 09:53:39 +0000 (+0000) Subject: re PR libstdc++/64798 (g++.old-deja/g++.eh/badalloc1.C FAILs) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8aa33fadbe1ca12a8e1c3b188a2301a0239e8e7b;p=gcc.git re PR libstdc++/64798 (g++.old-deja/g++.eh/badalloc1.C FAILs) 2015-01-28 Richard Biener PR libstdc++/64798 * libsupc++/eh_alloc.cc (struct allocated_entry): Align data member. (pool::allocate): Adjust allocation size and alignment to that change. (pool::free): Adjust pointer offsetting. From-SVN: r220201 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 169f02e0312..865e79b48da 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2015-01-28 Richard Biener + + PR libstdc++/64798 + * libsupc++/eh_alloc.cc (struct allocated_entry): Align + data member. + (pool::allocate): Adjust allocation size and alignment to + that change. + (pool::free): Adjust pointer offsetting. + 2015-01-27 Jonathan Wakely PR libstdc++/64368 diff --git a/libstdc++-v3/libsupc++/eh_alloc.cc b/libstdc++-v3/libsupc++/eh_alloc.cc index c77f53fdf02..7ddd2b746d8 100644 --- a/libstdc++-v3/libsupc++/eh_alloc.cc +++ b/libstdc++-v3/libsupc++/eh_alloc.cc @@ -94,7 +94,7 @@ namespace }; struct allocated_entry { std::size_t size; - char data[]; + char data[] __attribute__((aligned)); }; // A single mutex controlling emergency allocations. @@ -133,17 +133,18 @@ namespace void *pool::allocate (std::size_t size) { __gnu_cxx::__scoped_lock sentry(emergency_mutex); - // We need an additional size_t member. - size += sizeof (std::size_t); + // We need an additional size_t member plus the padding to + // ensure proper alignment of data. + size += offsetof (allocated_entry, data); // And we need to at least hand out objects of the size of // a freelist entry. if (size < sizeof (free_entry)) size = sizeof (free_entry); - // And we need to align objects we hand out to the required - // alignment of a freelist entry (this really aligns the + // And we need to align objects we hand out to the maximum + // alignment required on the target (this really aligns the // tail which will become a new freelist entry). - size = ((size + __alignof__(free_entry) - 1) - & ~(__alignof__(free_entry) - 1)); + size = ((size + __alignof__ (allocated_entry::data) - 1) + & ~(__alignof__ (allocated_entry::data) - 1)); // Search for an entry of proper size on the freelist. free_entry **e; for (e = &first_free_entry; @@ -185,7 +186,7 @@ namespace { __gnu_cxx::__scoped_lock sentry(emergency_mutex); allocated_entry *e = reinterpret_cast - (reinterpret_cast (data) - sizeof (std::size_t)); + (reinterpret_cast (data) - offsetof (allocated_entry, data)); std::size_t sz = e->size; if (!first_free_entry) {