https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83444
Bug ID: 83444 Summary: [5/6/7/8 Regression] missing strlen optimization on a member array of a local struct Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC 4.9 is the last release to transform both of the functions below into a no-op. Starting with 5.1, only the first function is so optimized while the second is not. $ cat z.c && gcc -O2 -S -Warray-bounds=2 -fdump-tree-optimized=/dev/stdout z.c void f (void) { char a[5] = "012"; __builtin_strcpy (a, ""); // folded into *a = 0 if (__builtin_strlen (a) != 0) // folded into false __builtin_abort (); // eliminated } void g (void) { char a[5] = "012"; char b[7] = ""; __builtin_strcpy (a, b); // folded into *a = 0 if (__builtin_strlen (a) != 0) // not folded __builtin_abort (); // not eliminated } ;; Function f (f, funcdef_no=0, decl_uid=1892, cgraph_uid=0, symbol_order=0) f (int i) { <bb 2> [local count: 1073741825]: return; } ;; Function g (g, funcdef_no=1, decl_uid=1896, cgraph_uid=1, symbol_order=1) g (int i) { char b[7]; char a[5]; char _1; unsigned char _9; <bb 2> [local count: 1073741825]: a = "012"; b = ""; _9 = MEM[(char * {ref-all})&b]; MEM[(char * {ref-all})&a] = _9; _1 = MEM[(const char *)&a]; if (_1 != 0) goto <bb 3>; [0.00%] else goto <bb 4>; [99.96%] <bb 3> [count: 0]: __builtin_abort (); <bb 4> [local count: 1073312327]: a ={v} {CLOBBER}; b ={v} {CLOBBER}; return; }