public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] ipa: check if cache_token != NULL before hash_set::add call
@ 2023-01-24 15:15 Martin Liška
  2023-02-01 14:11 ` Martin Jambor
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2023-01-24 15:15 UTC (permalink / raw)
  To: gcc-patches; +Cc: Martin Jambor, Jan Hubicka

We should not insert an empty value to the container.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR ipa/108509

gcc/ChangeLog:

	* cgraphunit.cc (walk_polymorphic_call_targets): Insert
	ony non-null values.
	* ipa.cc (walk_polymorphic_call_targets): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/ipa/pr108509.C: New test.
---
 gcc/cgraphunit.cc                   |  2 +-
 gcc/ipa.cc                          |  2 +-
 gcc/testsuite/g++.dg/ipa/pr108509.C | 22 ++++++++++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr108509.C

diff --git a/gcc/cgraphunit.cc b/gcc/cgraphunit.cc
index 832818d651f..a972900900b 100644
--- a/gcc/cgraphunit.cc
+++ b/gcc/cgraphunit.cc
@@ -1000,7 +1000,7 @@ walk_polymorphic_call_targets (hash_set<void *> *reachable_call_targets,
     = possible_polymorphic_call_targets
 	(edge, &final, &cache_token);
 
-  if (!reachable_call_targets->add (cache_token))
+  if (cache_token != NULL && !reachable_call_targets->add (cache_token))
     {
       if (symtab->dump_file)
 	dump_possible_polymorphic_call_targets 
diff --git a/gcc/ipa.cc b/gcc/ipa.cc
index 4de605000b6..5c15b60a603 100644
--- a/gcc/ipa.cc
+++ b/gcc/ipa.cc
@@ -182,7 +182,7 @@ walk_polymorphic_call_targets (hash_set<void *> *reachable_call_targets,
     = possible_polymorphic_call_targets
 	(edge, &final, &cache_token);
 
-  if (!reachable_call_targets->add (cache_token))
+  if (cache_token != NULL && !reachable_call_targets->add (cache_token))
     {
       for (i = 0; i < targets.length (); i++)
 	{
diff --git a/gcc/testsuite/g++.dg/ipa/pr108509.C b/gcc/testsuite/g++.dg/ipa/pr108509.C
new file mode 100644
index 00000000000..2844189bbb4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr108509.C
@@ -0,0 +1,22 @@
+// PR ipa/108509
+// { dg-do compile }
+// { dg-options "-O1 -fdevirtualize -fno-tree-fre" }
+
+struct B {
+  virtual void deref ();
+};
+
+struct RefPtr {
+  B *p;
+
+  RefPtr ()
+  {
+    p->deref ();
+  }
+};
+
+void
+f ()
+{
+  RefPtr b;
+}
-- 
2.39.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-01 14:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 15:15 [PATCH] ipa: check if cache_token != NULL before hash_set::add call Martin Liška
2023-02-01 14:11 ` Martin Jambor

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