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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
The inequality (__builtin_strlen (a4) != 0) is folded into (a4[0] != 0) very
early on during Gimplification so the strlen pass never sees it.

What the strlen pass should be able to do is fold strlen(a4) below to zero:

  int g (void)
  {
    __builtin_memset (a4, 0, sizeof a4);
    return __builtin_strlen (a4);   // not folded
  }

But handle_builtin_memset doesn't have the logic.  memcpy does so when the
above is change to the below it works:

  int g (void)
  {
    __builtin_memcpy (a4, (char[sizeof a4]){ }, sizeof a4);
    return __builtin_strlen (a4);   // folded to zero
  }

Reply via email to