]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Do not pass NULL to memset in ssa_global_cache.
authorAldy Hernandez <aldyh@redhat.com>
Sun, 14 Nov 2021 10:27:32 +0000 (11:27 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Sun, 14 Nov 2021 13:13:55 +0000 (14:13 +0100)
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.

gcc/gimple-range-cache.cc
gcc/testsuite/gcc.dg/pr103229.c [new file with mode: 0644]

index a63e20e7e498a86753a43861555327d5f41edc6a..b347edeb474077d1cebb65da87cccd382cdbb06f 100644 (file)
@@ -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 (file)
index 0000000..96ef9af
--- /dev/null
@@ -0,0 +1,10 @@
+// { dg-do compile }
+// { dg-options "-O -w" }
+
+int main() {
+  int i;
+  for (; i;)
+    ;
+
+  return 0;
+}