public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5629] ipa: check if cache_token != NULL before hash_set::add call
@ 2023-02-01 14:18 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2023-02-01 14:18 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:78589691ee158e689fa9bb7dec1165da475ea634

commit r13-5629-g78589691ee158e689fa9bb7dec1165da475ea634
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Jan 24 14:39:11 2023 +0100

    ipa: check if cache_token != NULL before hash_set::add call
    
    We should not insert an empty value to the container.
    
            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.

Diff:
---
 gcc/cgraphunit.cc                   |  2 +-
 gcc/ipa.cc                          |  2 +-
 gcc/testsuite/g++.dg/ipa/pr108509.C | 22 ++++++++++++++++++++++
 3 files changed, 24 insertions(+), 2 deletions(-)

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;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-01 14:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-01 14:18 [gcc r13-5629] ipa: check if cache_token != NULL before hash_set::add call Martin Liska

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