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

--- Comment #2 from Christian Franke <franke at computer dot org> ---
Sorry, but I disagree that this report is INVALID.

Unlike for example -Wstringop-overflow, warnings like -Wstring-compare should
IMO only occur if the warning condition holds for *all* function calls
generated by loop unrolling.

BTW, if the partial loop unrolling is done manually, the warning should occur,
but does not:

int f(const char * p, int n)
{
  char buf[10] = {0, };
  int i = 0;
  if (n <= 0) {
    if (!__builtin_strncmp(buf, "12345", 5) // <== no warning
        && (i == 5 || buf[5] == ' ')) // <== warning if removed
      return 1;
  }
  else {
    do {
      buf[i] = p[i]; i++;
    } while (i < (int)sizeof(buf)-1 && i < n);
    if (!__builtin_strncmp(buf, "12345", 5)
        && (i == 5 || buf[5] == ' '))
      return 1;
  }
  return 0;
}

With the above code, the warning occurs if the condition "&& (i == 5 || buf[5]
== ' ')" is removed. If this is done in the original testcase, the warning does
no longer occur.

Reply via email to