public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub 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: Tue, 29 Aug 2023 16:55:52 +0000	[thread overview]
Message-ID: <bug-110914-4-uLL7EiQ3s3@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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 55813
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55813&action=edit
gcc14-pr110914.patch

Untested fix.

The bogus change in the above mentioned commit was the:
   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);
+    }
part.  I haven't analyzed what exactly maybe_warn_overflow does, it is some
warning stuff and perhaps can be called when len is not constant, but the
previous guarding of adjust_last_stmt was completely intentional.
As adjust_last_stmt function comment says:
    If the last .MEM setter statement before STMT is
    memcpy (x, y, strlen (y) + 1), the only .MEM use of it is STMT
    and STMT is known to overwrite x[strlen (x)], adjust the last memcpy to
    just memcpy (x, y, strlen (y)).  SI must be the zero length
    strinfo.
so obviously the fact that memcpy (the second one) doesn't have last argument
constant 0 doesn't mean that it is non-zero length memcpy, we only know it
either if it is constant non-zero length, or variable where say value-range
could prove it is not zero.  We have an adjust_last_stmt call later in the
function which handles length of strlen (x) + 1 though.  So, this patch just
reverts the guard of that function back to what it was before.

  parent reply	other threads:[~2023-08-29 16:55 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 [this message]
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
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-uLL7EiQ3s3@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).