public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5242] Do not pass NULL to memset in ssa_global_cache.
@ 2021-11-14 13:15 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2021-11-14 13:15 UTC (permalink / raw)
  To: gcc-cvs

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

commit r12-5242-ga7ef5da3a9c348c35abb72d6f64f209f5661cfa4
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Sun Nov 14 11:27:32 2021 +0100

    Do not pass NULL to memset in ssa_global_cache.
    
    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.
    
    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.

Diff:
---
 gcc/gimple-range-cache.cc       |  3 ++-
 gcc/testsuite/gcc.dg/pr103229.c | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

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;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-14 13:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-14 13:15 [gcc r12-5242] Do not pass NULL to memset in ssa_global_cache Aldy Hernandez

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).