public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7916] store-merging: Avoid ICEs on roughly ~0ULL/8 sized stores [PR105094]
Date: Wed, 30 Mar 2022 08:21:56 +0000 (GMT)	[thread overview]
Message-ID: <20220330082156.E04B33858403@sourceware.org> (raw)

https://gcc.gnu.org/g:387e818cda0ffde86f624228c3da1ab28f453685

commit r12-7916-g387e818cda0ffde86f624228c3da1ab28f453685
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Mar 30 10:21:16 2022 +0200

    store-merging: Avoid ICEs on roughly ~0ULL/8 sized stores [PR105094]
    
    On the following testcase on 64-bit targets, store-merging sees
    a MEM_REF store from {} ctor with "negative" bitsize where bitoff + bitsize
    wraps around to very small end offset.  This later confuses the code
    so that it allocates just a few bytes of memory but fills in huge amounts of
    it.  Later on there is a param_store_merging_max_size size check but due to
    the wrap-around we pass that.
    
    The following patch punts on such large bitsizes.
    
    2022-03-30  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/105094
            * gimple-ssa-store-merging.cc (mem_valid_for_store_merging): Punt if
            bitsize <= 0 rather than just == 0.
    
            * gcc.dg/pr105094.c: New test.

Diff:
---
 gcc/gimple-ssa-store-merging.cc |  2 +-
 gcc/testsuite/gcc.dg/pr105094.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-ssa-store-merging.cc b/gcc/gimple-ssa-store-merging.cc
index e2e2157f1cb..b952ce57917 100644
--- a/gcc/gimple-ssa-store-merging.cc
+++ b/gcc/gimple-ssa-store-merging.cc
@@ -4940,7 +4940,7 @@ mem_valid_for_store_merging (tree mem, poly_uint64 *pbitsize,
   tree base_addr = get_inner_reference (mem, &bitsize, &bitpos, &offset, &mode,
 					&unsignedp, &reversep, &volatilep);
   *pbitsize = bitsize;
-  if (known_eq (bitsize, 0))
+  if (known_le (bitsize, 0))
     return NULL_TREE;
 
   if (TREE_CODE (mem) == COMPONENT_REF
diff --git a/gcc/testsuite/gcc.dg/pr105094.c b/gcc/testsuite/gcc.dg/pr105094.c
new file mode 100644
index 00000000000..da6dc172a64
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105094.c
@@ -0,0 +1,13 @@
+/* PR tree-optimization/105094 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+struct S { short a; char b[~(__SIZE_TYPE__)0 / __CHAR_BIT__ - 1]; };
+void bar (struct S *);
+
+void
+foo (void)
+{
+  struct S s = { 5 };
+  bar (&s);
+}


                 reply	other threads:[~2022-03-30  8:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220330082156.E04B33858403@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@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).