I guess I can imagine that macro expansion might result in some
cases where strict-aliasing is of benefit. Most people fail to use a
temporary in a macro, probably because __typeof__ is gcc-only.
I can probably fit 20 lines of code on a readable slide. Ideas?
In C++, this:
f (vector <float> &vec)
{
vector <float>::iterator it;
for (it = vec.begin (); it != vec.end (); it++)
...
}
will expand exactly to
f (vector <float> *vec)
{
float *it;
for (it = vec->data; it != vec->data + vec->size; it++)
...
}
There are no macros involved. You just need to find whether vec->size
is invariant. GCC is nowhere near performing whole program
optimization, so it has to punt quite often (plus there is the issue
with "char" aliasing everything, which however can be worked around by
field-sensitive alias analysis), but you have to start from something.
BTW, there are more normal programming habits that defeat
type-based alias analysis. People pick data types by habit.
Mostly, people will use the same type for nearly everything.
That's a problem with C, not with GCC. Plus, in the nastiest
template-metaprogramming-heavy math code this is not necessarily an
obstacle. Everything is inlined in the main loop, so there is no need
for whole program optimization. You use int or long for counters, float
or double for data: that's enough for type-based alias analysis to work
egregiously, coupled with some base/offset alias analysis to
disambiguate between different data structures used at the same time.
Richard Guenther can provide data for his favorite application (a
physics simulation) without and with -fstrict-aliasing. I bet it makes
a difference (and if not, it's a bug in GCC).
Paolo