https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98975
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> --- That is not what the UB in the testcase is, it is the out of bound accesses to the array - arr[2] and above. The bsort function has auto return type, but as there is no return, it is deduced to be void. And the UB would be there even with j < 3 instead of i < 3 (and even with j < 2).