This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/80576] New: dead strcpy and strncpy followed by memset not eliminated


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80576

            Bug ID: 80576
           Summary: dead strcpy and strncpy followed by memset 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: ---

Similar to bug 80487, due to the subsequent memset that overwrites the contents
of the destination arrays, the strcpy and strncpy calls in the following two
functions constitute dead stores and could be eliminated.  The output shows
that GCC does not yet take advantage of this optimization opportunity.  The
first case might be related to (or the same as) bug 79716.

$ cat y.c && gcc  -O2 -S -Wall -Wextra -Wpedantic
-fdump-tree-optimized=/dev/stdout y.c
void sink (void*);

void f (const char *s)
{
  char a[256];

  __builtin_strcpy (a, s);   // dead store
  __builtin_memset (a, 0, sizeof a); 

  sink (a);
}

void g (const char *s)
{
  char a[256];

  __builtin_strncpy (a, s, sizeof a);   // dead store
  __builtin_memset (a, 0, sizeof a);   

  sink (a);
}


;; Function f (f, funcdef_no=0, decl_uid=1795, cgraph_uid=0, symbol_order=0)

f (const char * s)
{
  char a[256];

  <bb 2> [100.00%]:
  __builtin_strcpy (&a, s_2(D));
  __builtin_memset (&a, 0, 256);
  sink (&a);
  a ={v} {CLOBBER};
  return;

}



;; Function g (g, funcdef_no=1, decl_uid=1799, cgraph_uid=1, symbol_order=1)

g (const char * s)
{
  char a[256];

  <bb 2> [100.00%]:
  __builtin_strncpy (&a, s_2(D), 256);
  __builtin_memset (&a, 0, 256);
  sink (&a);
  a ={v} {CLOBBER};
  return;

}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]