public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Subject: [COMMITTED] Do not pass NULL to memset in ssa_global_cache.
Date: Sun, 14 Nov 2021 14:15:00 +0100	[thread overview]
Message-ID: <20211114131500.1091155-1-aldyh@redhat.com> (raw)

The code computing ranges in PHIs in the path solver reuses the
temporary ssa_global_cache by calling its clear method.  Calling it on
an empty cache causes us to call memset with NULL.

[The testcase doesn't fail without the patch.  I suppose it needs some
usbsan magic, or to live somewhere else?]

Tested on x86-64 Linux.

gcc/ChangeLog:

	PR tree-optimization/103229
	* gimple-range-cache.cc (ssa_global_cache::clear): Do not pass
	null value to memset.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr103229.c: New test.
---
 gcc/gimple-range-cache.cc       |  3 ++-
 gcc/testsuite/gcc.dg/pr103229.c | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr103229.c

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index a63e20e7e49..b347edeb474 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -651,7 +651,8 @@ ssa_global_cache::clear_global_range (tree name)
 void
 ssa_global_cache::clear ()
 {
-  memset (m_tab.address(), 0, m_tab.length () * sizeof (irange *));
+  if (m_tab.address ())
+    memset (m_tab.address(), 0, m_tab.length () * sizeof (irange *));
 }
 
 // Dump the contents of the global cache to F.
diff --git a/gcc/testsuite/gcc.dg/pr103229.c b/gcc/testsuite/gcc.dg/pr103229.c
new file mode 100644
index 00000000000..96ef9aff67c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103229.c
@@ -0,0 +1,10 @@
+// { dg-do compile }
+// { dg-options "-O -w" }
+
+int main() {
+  int i;
+  for (; i;)
+    ;
+
+  return 0;
+}
-- 
2.31.1


             reply	other threads:[~2021-11-14 13:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-14 13:15 Aldy Hernandez [this message]
2021-11-14 13:53 ` Martin Liška
2021-11-14 15:18   ` Aldy Hernandez

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=20211114131500.1091155-1-aldyh@redhat.com \
    --to=aldyh@redhat.com \
    --cc=gcc-patches@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).