[Bug libstdc++/29286] [4.0/4.1/4.2/4.3 Regression] placement new does not change the dynamic type as it should
mark at codesourcery dot com
gcc-bugzilla@gcc.gnu.org
Tue May 22 15:05:00 GMT 2007
------- Comment #106 from mark at codesourcery dot com 2007-05-22 16:04 -------
Subject: Re: [4.0/4.1/4.2/4.3 Regression] placement
new does not change the dynamic type as it should
rguenth at gcc dot gnu dot org wrote:
> - we _cannot_ sink loads across stores.
>
> x = *int;
> *double = 1.0;
>
> the store to double may change the dynamic type of what *int
> points to.
To be clear, you mean something like this, right:
int i;
int *ip = &i;
double *dp = (double *)&i;
int x;
x = *ip;
*dp = 1.0;
?
I think that considering this code valid, and, therefore, forbidding the
interchange of the last two statements, requires a perverse reading of
the standard. Placement new allows you to change the dynamic type of
storage; I don't think that just writing through a pointer does. A key
goal of C++ relative to C was better type-safety. The placement new
operator provides a facility for explicitly controlling object lifetime,
for programmers that need this.
Before we do anything to support the case above, we should have a
crystal-clear ruling from the committee that says this is valid.
Otherwise, this is exactly the kind of optimization that TBAA was
designed to perform.
For history, the reason I implemented TBAA in GCC was that the SGI
MIPSPro C/C++ compiler did these kinds of optimizations ten years ago,
and I was trying to catch us up when looking at POOMA performance on
IRIX. G++ has had the freedom to interchange those stores for a long
time, and I believe it should continue to have that choice.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29286
More information about the Gcc-bugs
mailing list