On 08.12.2009 20:57, Martin Olsson wrote:
> Roland Scheidegger wrote:
>> Keith,
>>
>> I think there might be some slight issue with some of the changes in the
>> drivers I did. In particular, I was under the impression it would be ok
>> to do something like
>> union a_union {
>>   int i;
>>   double d;
>> };
>> int f() {
>>    double d = 3.0;
>>    return ((union a_union *) &d)->i;
>> };
>> but in fact gcc manpage tells me it's not (the example is from gcc 4.4
>> manpage) 
> 
> I think the issue you are describing is explained here:
> http://patrakov.blogspot.com/2009/03/dont-use-old-dtoac.html
Yes, probably. Note though it says gcc generates warnings for it, which
didn't happen, so I think gcc would actually not miscompile it.
(I suspect gcc doesn't complain and does not miscompile as long as it
can't determine the original type of the value). Still, the explanation
is imho not really satisfactory. I think a lot of people used to think
this would be perfectly fine (see for instance
http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
"casting through a union (2)").


> Also note the link he posts to the GCC manual:
> http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Optimize-Options.html#index-fstrict_002daliasing-721
Yep, that's the same stuff I used for the example.

Roland

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to