I have a very large module, which contains a few places where a pointer
is cast based on a templated data type.
Typically a pointer is created using a templated type, then copied as a
void*, then used as the templated type. In one of those places, the
optimizer removes the copy step, which is correct behavior for the
optimizer under strict aliasing, but of course incorrect for the program.
Because of the way the templating fits in, it would be very hard to
either make a correct union for the pointer, or do the copy using the
correct type.
Creating, copying and using the pointer are coded in different sub
projects in code templated on different things, but all of which might
be brought together by inlining (so the optimizer can do this damage).
If I compile the whole module with no-strict-alias it runs correctly,
but the generated code is 3% bigger and I think runs significantly
slower (I can only approximate how fast the broken code runs).
It would be great to have some attribute one could define on a pointer
to say that pointer violates strict aliasing. The pointers described
above are actually used through another layer of pointer, which is
declared as a void**. In concept the code looks like:
Datatype* a;
void** x = malloc ...
(Datatype*&)(x[n]) = a;
void** y = malloc ...
y[n] = x[n];
Datatype* b;
b = (Datatype*&)(y[n]);
So if there were a way to put an attribute on x and y to say they
violate strict aliasing, that would be a perfect solution.
Alternately, if violation of strict aliasing could be applied to inline
function definitions, that might be reasonable (hopefully just applying
to the operations inside that function, not to the whole function into
which it gets inlined).