https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108695
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Martin Liška from comment #6) > Yes, I'm also suspecting this code and I can verify that using optimize("O0") > for rijndaelEncrypt fixes the issue. > > The thing below is cast from 'const u8 *' and I thought it's valid to case > to 'u32 *' and then access it. Can you explain to me how exactly the > violation happens? A cast is fine, what matters are the accesses. If the object has u32 type, then casting its address to const u8 * and later on back to u32 * and accessing through that type is fine, but if it has an incompatible type, it is not. Similarly, if it is heap allocated, the type is given to it through the stores to it and later reads from it should be done with a compatible (aliasing wise) type. See section 6.5 in e.g. C17 for the details (definition of effective type and the aliasing requirements).