https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116672
Bug ID: 116672 Summary: gcc-11 and higher versions failed to check the strict-aliasing rule. Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zzy439...@alibaba-inc.com Target Milestone: --- The error occurs when I run the following code with GCC 11 and higher versions, and turn on -O2 flag. ---test.c--- #include <ctype.h> #include <stdio.h> static void func (const unsigned char **pstr) { while (isdigit(*++(*pstr))) continue; } int main() { const char *f = "1a"; func ((const unsigned char **) &f); printf("%s\n", f); return 0; } --- The command is: $gcc-11 -O2 test.c -o test It should outputs "a", but actually it outputs "1a". While I know the code is not comply to the strict-aliasing rule that opened by default with -O2 optimization, but the error only occurs in GCC 11 and higher versions. It seems that lower versions would check if the code is comply to the strict-aliasing rule, while the higher versions will not.