Re: ctor unnecessarily wiping of PODs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On 19 March 2012 17:12, Hite, Christopher wrote:
> Hi,
>
> I think I've got an optimizer bug producing a bzero of data that doesn't need initialization.
>
> Whether Ray has a ctor defined or not gcc wipes the memory 257 words for no reason.  What does have an effect is if you call the ctor of just  Ray it doesn't clear the data.
>
> One would expect none of the PODs to be inited unless explicitly done so in the code
>
> I'm guessing there's some kind of a bzero optimization where padding and non-inited PODs can be cleared along with several fields that need to be.  I'm guessing that this optimization is broken somehow.
>
> I'm getting this on gcc 4.6.0 debug and O3.
>
> struct Ray{
>        unsigned n;g
>        int u[0x100];
>        //Ray() : n() {}
> };
>
> struct Ray2: Ray {};
>
> void makeRay(void*v){
>        new(v)Ray2();

The C++ standard says that for a POD type the initializer () will
cause it to be zero-initialized.

If that's not what you want, use:
     new (v) Ray2;



[Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

Add to Google