Why type-punning breaks strict-aliasing
labs.qt.nokia.com
labs.qt.nokia.com
It's easy to claim that these uses don't exist, but they do occur in every larger piece of C software (especially when that large piece of software has performance-critical parts, which is increasingly the main use of C). And in both cases, the compiler breaks cases where the aliasing is introduced in the current function, and also exploited there; this should be reasonably easy to detect (compared to the general aliasing problem, which is unsolvable).
In some cases, declaring alignment may be hard to do portably; it's probably possible to use union tricks to force there to exist a dummy statement that implies certain alignment without breaking the aliasing rules, but I don't know for sure since I haven't run into such cases in practice yet.
As a nonrepresentative example, the simple function:
uint64_t foo(char x[8]) {
uint64_t y; memcpy(&y, &x[0], 8); return y;
}
gets compiled into a single « movq (%rdi), %rax » by gcc -S -O2 on my AMD64 machine with GCC 4.6.1.