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.
This commit is contained in:
Aldy Hernandez 2021-11-14 11:27:32 +01:00
parent 5a6100a255
commit a7ef5da3a9
2 changed files with 12 additions and 1 deletions

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

View File

@ -0,0 +1,10 @@
// { dg-do compile }
// { dg-options "-O -w" }
int main() {
int i;
for (; i;)
;
return 0;
}