public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Cc: Martin Jambor <mjambor@suse.cz>, Jan Hubicka <hubicka@ucw.cz>
Subject: [PATCH] ipa: check if cache_token != NULL before hash_set::add call
Date: Tue, 24 Jan 2023 16:15:05 +0100	[thread overview]
Message-ID: <196e54c5-4ee3-2d0b-3803-8b574eb71b99@suse.cz> (raw)

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


             reply	other threads:[~2023-01-24 15:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 15:15 Martin Liška [this message]
2023-02-01 14:11 ` Martin Jambor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=196e54c5-4ee3-2d0b-3803-8b574eb71b99@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=mjambor@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).