[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug tree-optimization/91315] New: missing strlen lower bound of a string known to be at least N cha
From:       "msebor at gcc dot gnu.org" <gcc-bugzilla () gcc ! gnu ! org>
Date:       2019-07-31 19:48:01
Message-ID: bug-91315-4 () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

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

            Bug ID: 91315
           Summary: missing strlen lower bound of a string known to be at
                    least N characters
           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: ---

In the program below the strlen pass tracks the (minimum) length of the string
formed by each of the functions, yet it doesn't expose that information to
downstream passes that could fold each of the tests to false on that basis.

$ cat z.c && gcc -O2  -Wall -S -fdump-tree-optimized=/dev/stdout z.c
char a[8];

void f0 (void)
{
  a[0] = '1';
  a[1] = '2';

  if (__builtin_strlen (a) < 2)
    __builtin_abort ();
}

void f1 (void)
{
  __builtin_memcpy (a, "123", 3);
  if (__builtin_strlen (a) < 3)
    __builtin_abort ();
}

void f2 (void)
{
  *__builtin_stpcpy (a, "123") = '4';
  if (__builtin_strlen (a) < 4)
    __builtin_abort ();

}


;; Function f0 (f0, funcdef_no=0, decl_uid=1909, cgraph_uid=1, symbol_order=1)

f0 ()
{
  long unsigned int _1;

  <bb 2> [local count: 1073741824]:
  MEM <unsigned short> [(char *)&a] = 12849;
  _1 = __builtin_strlen (&a);
  if (_1 <= 1)
    goto <bb 3>; [0.00%]
  else
    goto <bb 4>; [100.00%]

  <bb 3> [count: 0]:
  __builtin_abort ();

  <bb 4> [local count: 1073741824]:
  return;

}



;; Function f1 (f1, funcdef_no=1, decl_uid=1912, cgraph_uid=2, symbol_order=2)

f1 ()
{
  long unsigned int _1;

  <bb 2> [local count: 1073741824]:
  __builtin_memcpy (&a, "123", 3);
  _1 = __builtin_strlen (&a);
  if (_1 <= 2)
    goto <bb 3>; [0.00%]
  else
    goto <bb 4>; [100.00%]

  <bb 3> [count: 0]:
  __builtin_abort ();

  <bb 4> [local count: 1073741824]:
  return;

}



;; Function f2 (f2, funcdef_no=2, decl_uid=1915, cgraph_uid=3, symbol_order=3)

f2 ()
{
  long unsigned int _1;

  <bb 2> [local count: 1073741824]:
  __builtin_memcpy (&a, "123", 3);
  MEM[(char *)&a + 3B] = 52;
  _1 = __builtin_strlen (&a);
  if (_1 <= 3)
    goto <bb 3>; [0.00%]
  else
    goto <bb 4>; [100.00%]

  <bb 3> [count: 0]:
  __builtin_abort ();

  <bb 4> [local count: 1073741824]:
  return;

}=
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic