This is the mail archive of the
mailing list for the GCC project.
Re: Strenghten assumption about dynamic type changes (placement new)
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Jan Hubicka <hubicka at ucw dot cz>
- Cc: Jason Merrill <jason at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 23 Jul 2014 11:06:33 +0200
- Subject: Re: Strenghten assumption about dynamic type changes (placement new)
- Authentication-results: sourceware.org; auth=none
- References: <20140702201805 dot GB15987 at kam dot mff dot cuni dot cz> <53B49446 dot 7090402 at redhat dot com> <20140708135023 dot GC27691 at kam dot mff dot cuni dot cz> <53C87213 dot 1050604 at redhat dot com> <20140718100335 dot GA7671 at kam dot mff dot cuni dot cz> <53CA76FF dot 8080101 at redhat dot com> <20140719154408 dot GA8665 at kam dot mff dot cuni dot cz> <CAFiYyc0hDA+9G+wBVkf8Gif8vsDdpvyf4r3X8P=7G-P=QaWwqQ at mail dot gmail dot com> <20140722135434 dot GA12329 at kam dot mff dot cuni dot cz> <CAFiYyc37YkpYFGX2WJ14BUyEQ5k6ggvLrntsemtMEmat+6RgXA at mail dot gmail dot com> <20140722151720 dot GA25121 at kam dot mff dot cuni dot cz>
On Tue, Jul 22, 2014 at 5:17 PM, Jan Hubicka <email@example.com> wrote:
>> I don't see why
>> long x;
>> Q *q = new (x) Q;
>> q->~Q ();
>> new (x) T;
>> would be invalid. I also don't see why
>> Q q;
>> q.~Q ();
>> new (&q) T;
>> would be. Object lifetime is precisely specified and I don't see where it is
>> tied to (static) storage lifetime.
> This is precisely the testcase I posted on beggining of this thread.
> I do not see how the testcases can work with aliasing rules in the case Q's and T's
> memory is known to not alias.
It works because of the well-defined memory model (with regarding to
TBAA) in the middle-end. Every store changes the dynamic type of
a memory location which means that you can only use TBAA for
true-dependence checks (not anti-dependence or write-dependence
That has been the way we operate since GCC 4.3 (if I remember
correctly). That's also the reason we don't have to special-case
unions in any tricky way (yeah, we still do - because of that
type-punning special case and RTL alias analysis not dealing with it).
> Either we need to define what is and is not supported or go for speculative devirt more often.
The GCC middle-end (which also has to deal with cross-language
cases!) has this specified very clearly.