[Project-managers] Re: [Coin-tlc] lots of things to test

Laszlo Ladanyi ladanyi at us.ibm.com
Mon Oct 1 07:01:43 EDT 2007


I could have made my post a bit clearer... these warnings appear when gcc is
used for compilation. They do come up on linux with gcc-4.2.1, but I think
they should show on any platform with gcc-3.4 or later.

--Laci

On Sun, 30 Sep 2007, Laszlo Ladanyi wrote:

> Just a note...
> 
> There are quite a number of warnings of the kind:
> "dereferencing type-punned pointer will break strict-aliasing rules".
> 
> These warnings are there, because we use -fstrict-alias when gcc is used to
> allow gcc to optimize better. However, I have found examples on the web where
> a code for which this warning was emitted had actually been miscompiled.
> 
> So what should we do? As a short term solution we can just remove
> -fstrict-alias, but it'd be better to get rid of the warning. It comes up
> when, e.g., a double* is assigned to an int* or any type of pointer is cast to
> a void*. The way to get rid of the warning is to use unions.
> 
> For example the following code triggers the warning (when the first part is
> taken):
> int hash(double value)
> {
> #if sizeof(int)*2 == sizeof(double)
> 	int *xx = (int*)(&value)
> 	xx[0] += xx[1];
> 	return xx[0];
> #else
> 	return (int) value;
> #endif
> }
> 
> But the equivalent code does not (and I don't think this is any slower, in
> fact it may well be faster since no memory dereferencing is needed, hence
> the whole thing can even be executed in registers):
> int hash(double value)
> {
> #if sizeof(int)*2 == sizeof(double)
> 	union { double d; int i[2]; } xx;
> 	xx.d = value;
> 	xx.i[0] += xx.i[1];
> 	return xx.i[0];
> #else
> 	return (int) value;
> #endif
> }
> 
> 
> Any thoughts?
> 
> Cheers,
> --Laci
> 
> _______________________________________________
> Project-managers mailing list
> Project-managers at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/project-managers
> 



More information about the Project-managers mailing list