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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:623c6fddd605f8f225142d714440320e4ef54d84

commit r10-5961-g623c6fddd605f8f225142d714440320e4ef54d84
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Wed Jan 15 01:28:43 2020 +0100

    tree-optimization: Fix tree dse of strncpy PR93249

    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.

    2020-01-15  Jakub Jelinek  <ja...@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.

Reply via email to