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/81810] New: unused strcpy to a local buffer not eliminated


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

            Bug ID: 81810
           Summary: unused strcpy to a local buffer not eliminated
           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 successfully eliminates the call to memcpy in f() whose result is unused
below but fails to eliminate the equally pointless call to strcpy() in g() or
the one to strncpy() in h().  This is a missed optimization opportunity.

$ cat a.c && gcc -O2 -S -Wall -Wextra -Wpedantic a.c
void f (const void *p, unsigned n)
{
  char a[8];
  __builtin_memcpy (a, p, n);
}

void g (const char *s)
{
  char a[8];
  __builtin_strcpy (a, s);
}

void h (const char *s)
{
  char a[8];
  __builtin_strncpy (a, s, sizeof a);
}


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

f (const void * p, unsigned int n)
{
  <bb 2> [100.00%] [count: INV]:
  return;

}



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

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

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

}



;; Function h (h, funcdef_no=2, decl_uid=1824, cgraph_uid=2, symbol_order=2)

h (const char * s)
{
  char a[8];

  <bb 2> [100.00%] [count: INV]:
  __builtin_strncpy (&a, s_2(D), 8);
  a ={v} {CLOBBER};
  return;

}

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