[committed] Add a few missing checks that IPA_NODE_REF is not NULL (PR 92454)

Message ID ri6h837kgjj.fsf@suse.cz
State New
Headers show
Series
  • [committed] Add a few missing checks that IPA_NODE_REF is not NULL (PR 92454)
Related show

Commit Message

Martin Jambor Nov. 13, 2019, 2:16 p.m.
Hi,

since IPA_NODE_REF does not create summaries now, IPA-CP's
spread_undeadness can attempt to dereference a NULL one when a thunk is
a part of an SCC in the call graph (because of speculative
devirtualization edges).  Fixed with checking that is not the case.

Bootstrapped and tested on x86_64-linux and and committed because three
fourths of the patch are from Honza's Bugzilla comment anyway.

Thanks,

Martin


2019-11-13  Jan Hubicka  <hubicka@ucw.cz>
	    Martin Jambor  <mjambor@suse.cz>

	PR ipa/92454
	* ipa-cp.c (spread_undeadness): Check that IPA_NODE_REF exists.
	(identify_dead_nodes): Likewise.

	testsuite/
	* g++.dg/ipa/pr92454.C: New test.
---
 gcc/ipa-cp.c                       |  7 +++---
 gcc/testsuite/g++.dg/ipa/pr92454.C | 38 ++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr92454.C

-- 
2.23.0

Patch

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index b1d899976e8..594cddc5959 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -4971,7 +4971,7 @@  spread_undeadness (struct cgraph_node *node)
 	callee = cs->callee->function_symbol (NULL);
 	info = IPA_NODE_REF (callee);
 
-	if (info->node_dead)
+	if (info && info->node_dead)
 	  {
 	    info->node_dead = 0;
 	    spread_undeadness (callee);
@@ -5009,18 +5009,19 @@  identify_dead_nodes (struct cgraph_node *node)
   struct cgraph_node *v;
   for (v = node; v; v = ((struct ipa_dfs_info *) v->aux)->next_cycle)
     if (v->local
+	&& IPA_NODE_REF (v)
 	&& !v->call_for_symbol_thunks_and_aliases
 	     (has_undead_caller_from_outside_scc_p, NULL, true))
       IPA_NODE_REF (v)->node_dead = 1;
 
   for (v = node; v; v = ((struct ipa_dfs_info *) v->aux)->next_cycle)
-    if (!IPA_NODE_REF (v)->node_dead)
+    if (IPA_NODE_REF (v) && !IPA_NODE_REF (v)->node_dead)
       spread_undeadness (v);
 
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
       for (v = node; v; v = ((struct ipa_dfs_info *) v->aux)->next_cycle)
-	if (IPA_NODE_REF (v)->node_dead)
+	if (IPA_NODE_REF (v) && IPA_NODE_REF (v)->node_dead)
 	  fprintf (dump_file, "  Marking node as dead: %s.\n", v->dump_name ());
     }
 }
diff --git a/gcc/testsuite/g++.dg/ipa/pr92454.C b/gcc/testsuite/g++.dg/ipa/pr92454.C
new file mode 100644
index 00000000000..de67c66aed0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr92454.C
@@ -0,0 +1,38 @@ 
+/* Originally PR ipa/91969, options adjusted for PR ipa/92454 */
+/* { dg-options "-O3 --param ipa-cp-eval-threshold=1" } */
+
+enum by
+{
+};
+class A
+{
+public:
+  class B
+  {
+  public:
+    virtual void m_fn2 (by) = 0;
+  };
+  virtual int m_fn1 ();
+  B *cf;
+};
+by a;
+class C : A, A::B
+{
+  void m_fn2 (by);
+};
+void C::m_fn2 (by) { cf->m_fn2 (a); }
+
+struct a
+{
+  virtual ~a ();
+};
+
+struct b
+{
+  virtual void d (...);
+};
+
+struct c : a, b
+{
+  void d (...) {}
+};