GDC2 [Re: GDC2 compilation warnings]
Leandro Lucarella
luca at llucax.com.ar
Wed Nov 24 11:02:48 PST 2010
Smurfette, el 24 de noviembre a las 11:30 me escribiste:
> bearophile Wrote:
>
> > > > ../../gcc/d/d-gcc-real.h: In member function ?const real_value& real_t::rv() const?:
> > > > ../../gcc/d/d-gcc-real.h:54: warning: dereferencing type-punned pointer will
> > > break strict-aliasing rules
> > >
> > > If you have a great idea to fix this warning, please send a patch.
> >
> > In GCC there is a switch that disables strict aliasing optimization.
> > I think if you use it the compiler gets a bit slower, but you will
> > also avoid bugs caused by this optimization, and maybe the warnings
> > too. Otherwise there are other ways to solve it, maybe using an
> > union to perform the pointer cast.
>
> I'm sure that after so many years (30+) of professional experience
> with C/C++/D/Java compilers, Walter knows much much better than you or
> GCC when this optimization can be done in unsafe manner. It's an error
> in the compiler heuristics.
No, it isn't. There are no "heuristics" in there. Type punning became
a "problem" in the GCC world just recently, because the compiler started
doing some optimizations assuming strict-aliasing rules. And strict
aliasing rules are specified in C99, so if the code is written for older
standards (or for C++98 like in this case, which I think it doesn't say
anything about strict-aliasing rules), is completely valid to use
type-punned pointers.
So, there are 2 possible paths, tell GCC not to be so harsh on non-C99
code and avoid using optimizations that assume no type-punned pointers
are dereferenced, or "fix" (quoted because is not really *broken*,
strictly speaking) the code so GCC can optimize it a little better.
--
Leandro Lucarella (AKA luca) http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Se ha dicho tanto que las apariencias engañan
Por supuesto que engañarán a quien sea tan vulgar como para creerlo
More information about the Digitalmars-d
mailing list