On Tue, 2007-11-06 at 07:49 -0800, Joe Buck wrote:
> On Wed, Nov 07, 2007 at 02:30:44AM +1100, skaller wrote:

> Now it appears that you want to make some kind of intermediate assumption
> (semi-strict aliasing?), where pointers of different types are allowed to
> alias while ints can't alias with pointers.  

Yes. I want layout compatible types to be allowed to alias but
not others. In other words, where the access would be valid
provided it isn't optimised, don't optimise it. But where
the access would not be valid, optimise away.

Roughly speaking I want structural typing instead of nominal
typing. That is, when -fno-strict-aliasing is specified
I still want the type based optimisations to be applied,
but I want them based on the underlying structural types, 
not nominal types.

So for example

        struct X { int x; };
        struct Y { int z; };

are distinct nominal types, but they're structurally equivalent.

This is what I had hoped the 'strict' in the switch meant:
it turned off *strictness* by relaxing the notion of type
from nominal to structural.. but still did the analysis
and optimisations.

In C++ this is essential because constructable types cannot
be aliased in a union. This problem doesn't arise like that
in C.

You may note that even C already has structural typing
and aliasing rules already apply it of necessity: 
technically a T* and a T const* are distinct types.
But clearly they can alias.

BTW: yes I understand I ask for something gcc may not be
doing, I'm not asking for a change, just to understand
what it actually does. I guess that the optimisations
are defeated by, for example, subroutine calls across
translation unit boundaries. This provides part of
what I want: local code is still optimised, but aliases
across unit boundaries aren't, so whilst that model
applies I don't actually need the switch.

Unfortunately there are other cases (in C++) where I have
to break the rules, but I still don't want optimisations
disabled in other code. I want my cake and to eat it too .. :)

Without delving into the Standard, nor gcc implementation,
there are clearly isolated place where the optimisation
must be disabled. The most obvious is C++ reinterpret_cast<>
which *always* breaks the strict aliasing rules .. that
is indeed its purpose. 


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

Reply via email to