public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/110914] [11/12/13/14 Regression] Optimization eliminating necessary assignment before 0-byte memcpy since r10-5451
Date: Wed, 30 Aug 2023 09:57:58 +0000	[thread overview]
Message-ID: <bug-110914-4-96S1lIVulB@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110914-4@http.gcc.gnu.org/bugzilla/>

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

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

https://gcc.gnu.org/g:cf3aa538317d6c525739f339b79010ae82dc20f5

commit r11-10969-gcf3aa538317d6c525739f339b79010ae82dc20f5
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Aug 30 11:21:45 2023 +0200

    tree-ssa-strlen: Fix up handling of conditionally zero memcpy [PR110914]

    The following testcase is miscompiled since r279392 aka
r10-5451-gef29b12cfbb4979
    The strlen pass has adjust_last_stmt function, which performs mainly strcat
    or strcat-like optimizations (say strcpy (x, "abcd"); strcat (x, p);
    or equivalent memcpy (x, "abcd", strlen ("abcd") + 1); char *q = strchr (x,
0);
    memcpy (x, p, strlen (p)); etc. where the first stmt stores '\0' character
    at the end but next immediately overwrites it and so the first memcpy can
be
    adjusted to store 1 fewer bytes.  handle_builtin_memcpy called this
function
    in two spots, the first one guarded like:
      if (olddsi != NULL
          && tree_fits_uhwi_p (len)
          && !integer_zerop (len))
        adjust_last_stmt (olddsi, stmt, false);
    i.e. only for constant non-zero length.  The other spot can call it even
    for non-constant length but in that case we punt before that if that length
    isn't length of some string + 1, so again non-zero.
    The r279392 change I assume wanted to add some warning stuff and changed it
    like
       if (olddsi != NULL
    -      && tree_fits_uhwi_p (len)
           && !integer_zerop (len))
    -    adjust_last_stmt (olddsi, stmt, false);
    +    {
    +      maybe_warn_overflow (stmt, len, rvals, olddsi, false, true);
    +      adjust_last_stmt (olddsi, stmt, false);
    +    }
    While maybe_warn_overflow possibly handles non-constant length fine,
    adjust_last_stmt really relies on length to be non-zero, which
    !integer_zerop (len) alone doesn't guarantee.  While we could for
    len being SSA_NAME ask the ranger or tree_expr_nonzero_p, I think
    adjust_last_stmt will not benefit from it much, so the following patch
    just restores the above condition/previous behavior for the
adjust_last_stmt
    call only.

    2023-08-30  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/110914
            * tree-ssa-strlen.c (strlen_pass::handle_builtin_memcpy): Don't
call
            adjust_last_stmt unless len is known constant.

            * gcc.c-torture/execute/pr110914.c: New test.

    (cherry picked from commit 398842e7038ea0f34054f0f694014d0ecd656846)

  parent reply	other threads:[~2023-08-30  9:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-05 15:46 [Bug c++/110914] New: Optimization eliminating necessary assignment before 0-byte memcpy erosenberger at kinetica dot com
2023-08-05 15:47 ` [Bug c++/110914] " erosenberger at kinetica dot com
2023-08-05 16:04 ` [Bug tree-optimization/110914] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-08-05 16:14 ` pinskia at gcc dot gnu.org
2023-08-29 15:50 ` [Bug tree-optimization/110914] [11/12/13/14 Regression] Optimization eliminating necessary assignment before 0-byte memcpy since r10-5451 jakub at gcc dot gnu.org
2023-08-29 16:55 ` jakub at gcc dot gnu.org
2023-08-30  9:22 ` cvs-commit at gcc dot gnu.org
2023-08-30  9:33 ` cvs-commit at gcc dot gnu.org
2023-08-30  9:49 ` cvs-commit at gcc dot gnu.org
2023-08-30  9:57 ` cvs-commit at gcc dot gnu.org [this message]
2023-08-30 10:00 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110914-4-96S1lIVulB@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).