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

--- Comment #27 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #26)
> I tried the __builtin_object_size patch and while it avoids the warning in
> the reported test case it's not effective in others derived from it, such as:
> 
> #include <string>
> 
> const char constantString[] = {42, 53};
> 
> void f(std::string& s, int n)
> {
>   if (n < 2) n = 2;
>   s.insert(0, static_cast<const char*>(constantString), n);
> }

That could be handled by doing:
__builtin_constant_p (__builtin_object_size (__s, 0) < (2 * __len2 - __len1) *
sizeof(_CharT))
&& __builtin_object_size (__s, 0) < (2 * __len2 - __len1) * sizeof(_CharT)
assuming VRP is able to determine the comparison is constant even when one of
the lengths are non-constant.

Reply via email to