[Bug tree-optimization/86708] New: strlen of an empty aggregate element or member string not folded

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jul 27 21:38:00 GMT 2018


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

            Bug ID: 86708
           Summary: strlen of an empty aggregate element or member string
                    not folded
           Product: gcc
           Version: 9.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 9 can fold explicitly initialized members of aggregates but it doesn't know
to do the same for members or array elements that are initialized implicitly to
the empty string, as in the following test case:

$ cat c.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout c.c
const char a[][4] = { "123" };

int f (int i)
{
  return __builtin_strlen (a[1]);   // not folded
}

const struct {
  char a[4], b[4];
} s = { "123" };

int g (int i)
{
  return __builtin_strlen (s.b);   // not folded
}


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

f (int i)
{
  long unsigned int _1;
  int _3;

  <bb 2> [local count: 1073741825]:
  _1 = __builtin_strlen (&a[1]);
  _3 = (int) _1;
  return _3;

}



;; Function g (g, funcdef_no=1, decl_uid=1906, cgraph_uid=2, symbol_order=3)

g (int i)
{
  long unsigned int _1;
  int _3;

  <bb 2> [local count: 1073741825]:
  _1 = __builtin_strlen (&s.b);
  _3 = (int) _1;
  return _3;

}


More information about the Gcc-bugs mailing list