https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80487
Bug ID: 80487
Summary: redundant memset/memcpy/strcpy calls not eliminated
Product: gcc
Version: 7.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: ---
Somewhat similar to bug 79716 but (IIUC) with a different root cause, the
redundant clearing of the array prior to the call to strncpy in the following
function is not eliminated as it could be. (Strncpy is specified to append
NULs to fill the destination.)
$ cat t.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout t.c
void sink (void*);
void f (const char *s)
{
char a[256] = ""; // redundant initialization
__builtin_strncpy (a, s, sizeof a);
sink (a);
}
void g (const char *s)
{
char a[256];
__builtin_memset (a, 0, sizeof a); // redundant memset
__builtin_strncpy (a, s, sizeof a);
sink (a);
}
;; Function f (f, funcdef_no=0, decl_uid=1797, cgraph_uid=0, symbol_order=0)
f (const char * s)
{
char a[256];
<bb 2> [100.00%]:
a = "";
__builtin_strncpy (&a, s_3(D), 256);
sink (&a);
a ={v} {CLOBBER};
return;
}
;; Function g (g, funcdef_no=1, decl_uid=1801, cgraph_uid=1, symbol_order=1)
g (const char * s)
{
char a[256];
<bb 2> [100.00%]:
__builtin_memset (&a, 0, 256);
__builtin_strncpy (&a, s_3(D), 256);
sink (&a);
a ={v} {CLOBBER};
return;
}