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

            Bug ID: 71303
           Summary: missing strlen optimization for strings initialized
                    via a braced-init-list
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

While continuing my exploration of tree-ssa-strlen.c I discovered that while
optimizes a strlen call when the argument is an array initialized using a
string (as in function f below), it doesn't optimize it when the argument is
initialized using the braced initializer-list (as in g below).  This is also
the root cause behind at least part of bug 71296.

(As a data point, Clang 3.8 emits optimal code for both functions in the test
case.)

$ cat strlen.c && /build/gcc-6-branch/gcc/xgcc -B /build/gcc-6-branch/gcc -O2
-S -Wall -Wextra -fdump-tree-optimized=/dev/stdout strlen.c 
int f (void)
{
  char s[] = "12345";
  return __builtin_strlen (s);
}

int g (void)
{
  char s[] = { '1', '2', '3', '4', '5', '\0' };
  return __builtin_strlen (s);
}

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

f ()
{
  <bb 2>:
  return 5;

}



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

g ()
{
  char s[6];
  long unsigned int _8;
  int _9;

  <bb 2>:
  s[0] = 49;
  s[1] = 50;
  s[2] = 51;
  s[3] = 52;
  s[4] = 53;
  s[5] = 0;
  _8 = __builtin_strlen (&s);
  _9 = (int) _8;
  s ={v} {CLOBBER};
  return _9;

}

Reply via email to