hash: do not insert deleted value to a hash_set

Message ID 7cb85a5f-98c7-a398-d7ec-40a170039830@suse.cz
State Not Applicable
Headers
Series hash: do not insert deleted value to a hash_set |

Checks

Context Check Description
snail/gcc-patch-check fail Git am fail log

Commit Message

Martin Liška Jan. 9, 2023, 10:52 a.m. UTC
  Hi.

After the new hash_set checking code, we face an issue where deleted value
is added to a hash_set. Fix it.

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

Ready to be installed?
Thanks,
Martin

	PR lto/108330

gcc/ChangeLog:

	* lto-cgraph.cc (compute_ltrans_boundary): Do not insert
	NULL (deleleted value) to a hash_set.

gcc/testsuite/ChangeLog:

	* g++.dg/ipa/pr108830.C: New test.
---
  gcc/lto-cgraph.cc                   |  3 ++-
  gcc/testsuite/g++.dg/ipa/pr108830.C | 20 ++++++++++++++++++++
  2 files changed, 22 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/ipa/pr108830.C
  

Comments

Richard Biener Jan. 9, 2023, 12:13 p.m. UTC | #1
On Mon, Jan 9, 2023 at 11:53 AM Martin Liška <mliska@suse.cz> wrote:
>
> Hi.
>
> After the new hash_set checking code, we face an issue where deleted value
> is added to a hash_set. Fix it.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

OK

> Thanks,
> Martin
>
>         PR lto/108330
>
> gcc/ChangeLog:
>
>         * lto-cgraph.cc (compute_ltrans_boundary): Do not insert
>         NULL (deleleted value) to a hash_set.
>
> gcc/testsuite/ChangeLog:
>
>         * g++.dg/ipa/pr108830.C: New test.
> ---
>   gcc/lto-cgraph.cc                   |  3 ++-
>   gcc/testsuite/g++.dg/ipa/pr108830.C | 20 ++++++++++++++++++++
>   2 files changed, 22 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/ipa/pr108830.C
>
> diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
> index eef5ea1d061..805c7855eb3 100644
> --- a/gcc/lto-cgraph.cc
> +++ b/gcc/lto-cgraph.cc
> @@ -918,7 +918,8 @@ compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
>               vec <cgraph_node *>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/pr108830.C b/gcc/testsuite/g++.dg/ipa/pr108830.C
> new file mode 100644
> index 00000000000..96656f67e4f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ipa/pr108830.C
> @@ -0,0 +1,20 @@
> +// PR lto/108330
> +// { dg-do compile }
> +
> +class A {
> +      virtual unsigned long m_fn1() const;
> +        virtual int &m_fn2(unsigned long) const;
> +};
> +class C : A {
> +public:
> +      int &m_fn2(unsigned long) const;
> +        unsigned long m_fn1() const;
> +};
> +class B {
> +      void m_fn3(const A &, const int &, const C &, int &) const;
> +};
> +void B::m_fn3(const A &, const int &, const C &, int &) const {
> +      C &a(a);
> +        for (long b = 0; a.m_fn1(); b++)
> +             a.m_fn2(0);
> +}
> --
> 2.39.0
>
  

Patch

diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index eef5ea1d061..805c7855eb3 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -918,7 +918,8 @@  compute_ltrans_boundary (lto_symtab_encoder_t in_encoder)
  	      vec <cgraph_node *>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/pr108830.C b/gcc/testsuite/g++.dg/ipa/pr108830.C
new file mode 100644
index 00000000000..96656f67e4f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ipa/pr108830.C
@@ -0,0 +1,20 @@ 
+// PR lto/108330
+// { dg-do compile }
+
+class A {
+      virtual unsigned long m_fn1() const;
+        virtual int &m_fn2(unsigned long) const;
+};
+class C : A {
+public:
+      int &m_fn2(unsigned long) const;
+        unsigned long m_fn1() const;
+};
+class B {
+      void m_fn3(const A &, const int &, const C &, int &) const;
+};
+void B::m_fn3(const A &, const int &, const C &, int &) const {
+      C &a(a);
+        for (long b = 0; a.m_fn1(); b++)
+	      a.m_fn2(0);
+}