On Tue, 26 Jun 2007, Andrew Pinski wrote:

> On 6/26/07, Herman Geza <[EMAIL PROTECTED]> wrote:
> > Maybe GCC shouldn't optimize around invalid type-punnings?
> 
> That is what -fno-strict-aliasing is for.
> Also GCC has done this since 3.0.0 (and also 2.95 and 2.95.1 and then
> in 2.95.2 it was changed back while most of the free source world
> fixes their code).

Let me elaborate.  If the compiler can detect invalid type-punning, 
then shouldn't optimize.  For example,

void foo(int *a, float *b) {
        // here, access to a and b can be optimized, as the compiler 
supposedly doesn't know whether a and b point to the same address
}

but:

void foo(float *a) {
        int *b = (int*)a; // type-punning warning

        // here, access to a and b shouldn't be optimized, as the compiler 
knows that a and b point to the same address
}

Is this reasonable?

Geza

Reply via email to