This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: New type-based pool allocator code miscompiled due to aliasing issue?
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Martin LiÅka <mliska at suse dot cz>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 16 Jun 2015 15:17:57 +0200
- Subject: Re: New type-based pool allocator code miscompiled due to aliasing issue?
- Authentication-results: sourceware.org; auth=none
- References: <20150611165115 dot E278EEDC at oc7340732750 dot ibm dot com> <60B0A9AA-8E0A-4538-8950-46224E08F1EA at gmail dot com> <20150611175036 dot GJ10247 at tucnak dot redhat dot com> <66F626EF-C978-4DB4-9474-185A2FC41047 at gmail dot com> <557E962C dot 5060501 at suse dot cz> <CA+=Sn1nubVp+KwFGahDZHLL7mWHk0=+ocmtxvnDW9MHtD42Q6Q at mail dot gmail dot com> <557EC3A0 dot 2080303 at suse dot cz> <alpine dot DEB dot 2 dot 20 dot 1506151930090 dot 1576 at laptop-mg dot saclay dot inria dot fr> <557FEBC9 dot 8080002 at suse dot cz>
On Tue, Jun 16, 2015 at 11:26 AM, Martin LiÅka <mliska@suse.cz> wrote:
> On 06/15/2015 07:31 PM, Marc Glisse wrote:
>> On Mon, 15 Jun 2015, Martin LiÅka wrote:
>>
>>> Ah, I overlooked that it's not a placement new, but just static casting.
>>> Anyway, if I added:
>>>
>>> cselib_val () {}
>>>
>>> to struct cselib_val and changed the cast to placement new:
>>> char *ptr = (char *) header;
>>> return new (ptr) T ();
>>>
>>> I got following compilation error:
>>>
>>> In file included from ../../gcc/alias.c:46:0:
>>> ../../gcc/alloc-pool.h: In instantiation of âT* pool_allocator<T>::allocate() [with T = cselib_val]â:
>>> ../../gcc/cselib.h:51:27: required from here
>>> ../../gcc/alloc-pool.h:416:23: error: no matching function for call to âcselib_val::operator new(sizetype, char*&)â
>>> return new (ptr) T ();
>>> ^
>>> In file included from ../../gcc/alias.c:47:0:
>>> ../../gcc/cselib.h:49:16: note: candidate: static void* cselib_val::operator new(size_t)
>>> inline void *operator new (size_t)
>>> ^
>>> ../../gcc/cselib.h:49:16: note: candidate expects 1 argument, 2 provided
>>
>> #include <new>
>>
>
> Hi.
>
> <new> header file is not missing (explicit addition of the file does not help).
> Feel free to play with following patch which should fix cselib.h compilation error.
cselib_val overrides the new operator but fails to provide an overload
for the placement new
form. Fix that and it should work (of course it gets quite awkward
with its 'new' calling
pool.allocate and its placement new doing value-construction then...)
Richard.
> Thanks,
> Martin