diff mbox series

IPA: Avoid segfault in devirtualization_time_bonus (PR 93223)

Message ID ri6o8v79qgu.fsf@suse.cz
State New
Headers show
Series IPA: Avoid segfault in devirtualization_time_bonus (PR 93223) | expand

Commit Message

Martin Jambor Jan. 13, 2020, 6:11 p.m. UTC
Hi,

the following patch fixes a segfault happening when IPA-CP tried to
evaluate benefits of inlining a function specifically compiled with -O0,
which therefore does not have an inline summary.   The fix is simply to
add the check.  Bootstrapped on x86_64-linux, Honza has just approved it
offline and I will commit it momentarily.

Thanks,

Martin


2020-01-13  Martin Jambor  <mjambor@suse.cz>

	PR ipa/93223
	* ipa-cp.c (devirtualization_time_bonus): Check whether isummary is
	NULL.

	testsuite/
	* g++.dg/ipa/pr93223.C: New test.
---
 gcc/ipa-cp.c                       |  2 +-
 gcc/testsuite/g++.dg/ipa/pr93223.C | 62 ++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr93223.C
diff mbox series

Patch

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 1c1103ca32b..1b8a5104a3d 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -3158,7 +3158,7 @@  devirtualization_time_bonus (struct cgraph_node *node,
       if (avail < AVAIL_AVAILABLE)
 	continue;
       isummary = ipa_fn_summaries->get (callee);
-      if (!isummary->inlinable)
+      if (!isummary || !isummary->inlinable)
 	continue;
 
       int size = ipa_size_summaries->get (callee)->size;
diff --git a/gcc/testsuite/g++.dg/ipa/pr93223.C b/gcc/testsuite/g++.dg/ipa/pr93223.C
new file mode 100644
index 00000000000..87f98b5e244
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr93223.C
@@ -0,0 +1,62 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -std=gnu++14" } */
+
+template <typename Function>
+bool run(const int item_count,
+         Function && process_range,
+         const int max_parallelism,
+         int* progress = nullptr)
+{
+    if (max_parallelism <= 1)
+    {
+        if (progress == nullptr)
+        {
+            return process_range(0);
+        }
+        else
+        {
+            auto result = true;
+            for (int i = 0; i != item_count && result; ++i)
+            {
+                (*progress)++;
+                result = process_range(i);
+            }
+            return result;
+        }
+    }
+
+    if (max_parallelism > 10)
+    {
+        if (progress == nullptr)
+        {
+            return process_range(0);
+        }
+        else
+        {
+            auto result = true;
+            for (int i = 0; i != item_count && result; ++i)
+            {
+                (*progress)++;
+                result = process_range(i);
+            }
+            return result;
+        }
+    }
+    return false;
+}
+
+namespace
+{
+__attribute__((optimize(0))) bool worker_fun(const int)
+{
+    return true;
+}
+}
+
+void demo(int n)
+{
+    for (int i = 0; i < n; ++i)
+    {
+        run(n, &worker_fun, n);
+    }
+}