[Bug tree-optimization/114385] -Wrestrict false positive creating std::string from iterators

2024-03-18 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114385

--- Comment #3 from Andrew Pinski  ---
I think this might be due to changes to std::copy which tries to skip memcpy if
it is only one element.

My bet is maybe std::copy could add `if (end < begin) __builtin_unreachable();`
in it and the code would be better optimized but then some warnings might not
show up.

Basically if I read this code correctly, the preconditions for this function is
 both begin and end are proper iterators and that `end >= begin` is holds true.

What is happening is GCC gets `end - begin < 2` but then does not know if that
could be negative and all things break lose.

[Bug tree-optimization/114385] -Wrestrict false positive creating std::string from iterators

2024-03-18 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114385

--- Comment #2 from Andrew Pinski  ---
This also works:
if (end < begin) __builtin_unreachable();

[Bug tree-optimization/114385] -Wrestrict false positive creating std::string from iterators

2024-03-18 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114385

--- Comment #1 from Andrew Pinski  ---
Another workaround is to add:

if (end-begin < 0) __builtin_unreachable();


I notice that this is not the same as:
[[assume(end-begin >= 0)]];

but that seems related to another bug report dealing with how we don't do
IPA_SRA over assume statements yet.