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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jan Hubicka from comment #5)
> I think this is a valid testcase showing that we can't optimize it:
> 
> #include<string>
> #include<cstdio>
> #include<cstring>
> int
> main()
> {
>         std::string str="";
>         str.push_back (0);
>         printf ("%i %i\n", str.length(), strlen (str.c_str()));
>         return 0;
> }

That is some other issue.
The strlen pass should have figured that out:
  MEM <vector(2) char> [(char_type &)&str + 16] = { 0, 0 };
  _1 = strlen (&str.D.25443._M_local_buf);

Reduced testcase for that:
```
struct f
{
  char s[2];
};
f s;
int f(void)
{
  char &t = s.s[0];
  char &t1 = s.s[1];
  t = 0;
  t1 = 0;
  int t0 =  __builtin_strlen(s.s);
  return t0;
}

```

Reply via email to