[PATCH] gcc_qsort: avoid overlapping memcpy (PR 86311)

Richard Biener richard.guenther@gmail.com
Mon Jun 25 16:31:00 GMT 2018


On June 25, 2018 4:52:43 PM GMT+02:00, Alexander Monakov <amonakov@ispras.ru> wrote:
>On Mon, 25 Jun 2018, Alexander Monakov wrote:
>> 
>> In PR 86311 Valgrind flags a call to memcpy with overlapping buffers.
>This can
>> happen in reorder{23,45} helpers when we're reordering in-place, and
>the 3rd/5th
>> element doesn't need to be moved: in that case the middle memcpy is
>called
>> with source == destination.
>> 
>> The fix is simple: just use a temporary, just like for other
>elements.
>
>Sigh - I see GCC optimizes memmove as well as memcpy in this case, so
>changing
>the offending memcpy calls to memmoves would be a bit cleaner. OK to go
>with
>this instead?

I think that's better. Or conditionalizing the offending ones on dest! = src? 

Richard. 

>Alexander



More information about the Gcc-patches mailing list