https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86265
Bug ID: 86265 Summary: Wrong code on an invalid code starting with r255790 Product: gcc Version: unknown Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: marxin at gcc dot gnu.org CC: msebor at gcc dot gnu.org Target Milestone: --- Starting from the mentioned revision we do: $ cat tester.c #include <stdio.h> #include <string.h> #define min(a, b) (((a) < (b)) ? (a) : (b)) struct S { char data[4]; char fallout[100]; }; int main(int argc, char **argv) { struct S s; strncpy(s.data, argv[1], 4 + 100); int length = min(strlen(s.data), 4); printf("length: %d\n", length); return 0; } $ gcc tester.c -O3 && ./a.out 123456 length: 6 before the mentioned revision we did: length: 4. optimized dumps: after revision: ;; Function main (main, funcdef_no=11, decl_uid=2580, cgraph_uid=11, symbol_order=11) (executed once) main (int argc, char * * argv) { struct S s; char * _1; long unsigned int _2; int iftmp.0_3; <bb 2> [local count: 1073741825]: _1 = MEM[(char * *)argv_4(D) + 8B]; strncpy (&s.data, _1, 104); _2 = strlen (&s.data); iftmp.0_3 = (int) _2; printf ("length: %d\n", iftmp.0_3); s ={v} {CLOBBER}; return 0; } before: ;; Function main (main, funcdef_no=11, decl_uid=2580, cgraph_uid=11, symbol_order=11) (executed once) main (int argc, char * * argv) { struct S s; char * _1; long unsigned int _2; int iftmp.0_3; long unsigned int _10; <bb 2> [local count: 1073741825]: _1 = MEM[(char * *)argv_4(D) + 8B]; strncpy (&s.data, _1, 104); _2 = strlen (&s.data); if (_2 <= 3) goto <bb 4>; [50.00%] else goto <bb 3>; [50.00%] <bb 3> [local count: 536870913]: <bb 4> [local count: 1073741825]: # _10 = PHI <_2(2), 4(3)> iftmp.0_3 = (int) _10; printf ("length: %d\n", iftmp.0_3); s ={v} {CLOBBER}; return 0; }