[PATCH] tree-optimization: Fix tree dse of strncpy PR93249

Jeff Law law@redhat.com
Wed Jan 15 02:06:00 GMT 2020


On Wed, 2020-01-15 at 00:53 +0100, Jakub Jelinek wrote:
> Hi!
> 
> As the testcase shows, tail trimming of strncpy in tree-ssa-dse.c is fine,
> we just copy or clear fewer bytes in the destination, but unlike
> memcpy/memset etc., head trimming is problematic in certain cases.
> If we can prove that there are no zero bytes among initial head_trim bytes,
> it is ok to trim it, if we can prove there is at least one zero byte among
> initial head_trim bytes, we could (not implemented in the patch) turn
> the strncpy into memset 0, but otherwise we need to avoid the head trimming,
> because the presence or absence of NUL byte there changes the behavior for
> subsequent bytes, whether further bytes from src are copied or if further
> bytes are cleared.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
> 
> 2020-01-15  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/93249
> 	* tree-ssa-dse.c: Include builtins.h and gimple-fold.h.
> 	(maybe_trim_memstar_call): Move head_trim and tail_trim vars to
> 	function body scope, reindent.  For BUILTIN_IN_STRNCPY*, don't
> 	perform head trim unless we can prove there are no '\0' chars
> 	from the source among the first head_trim chars.
> 
> 	* gcc.c-torture/execute/pr93249.c: New test.
OK
jeff
> 



More information about the Gcc-patches mailing list