public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Jambor <jamborm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-5630] ipa-param-manip: Be careful about a reallocating hash_map
Date: Tue, 30 Nov 2021 14:36:48 +0000 (GMT)	[thread overview]
Message-ID: <20211130143648.1E9AD3858408@sourceware.org> (raw)

https://gcc.gnu.org/g:b3f60112edcb85b459e60f66c44a55138b1cef49

commit r12-5630-gb3f60112edcb85b459e60f66c44a55138b1cef49
Author: Martin Jambor <mjambor@suse.cz>
Date:   Tue Nov 30 15:35:18 2021 +0100

    ipa-param-manip: Be careful about a reallocating hash_map
    
    PR 103449 revealed that when I was storing result of one hash_map
    lookup into another entry in the hash_map, I was still accessing the
    entry in the table, which meanwhile could get reallocated, making the
    accesses invalid-after-free.
    
    Fixed with the following, which also simplifies the return statement
    which must have been true even now.
    
    gcc/ChangeLog:
    
    2021-11-29  Martin Liska  <mliska@suse.cz>
                Martin Jambor  <mjambor@suse.cz>
    
            PR ipa/103449
            * ipa-param-manipulation.c
            (ipa_param_body_adjustments::prepare_debug_expressions): Be
            careful about hash_map reallocating itself.  Simpify a return
            which always returns true.

Diff:
---
 gcc/ipa-param-manipulation.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c
index 479c20b3871..163af94cde0 100644
--- a/gcc/ipa-param-manipulation.c
+++ b/gcc/ipa-param-manipulation.c
@@ -1279,9 +1279,10 @@ ipa_param_body_adjustments::prepare_debug_expressions (tree dead_ssa)
       if (gimple_assign_copy_p (def)
 	  && TREE_CODE (gimple_assign_rhs1 (def)) == SSA_NAME)
 	{
-	  tree *d = m_dead_ssa_debug_equiv.get (gimple_assign_rhs1 (def));
-	  m_dead_ssa_debug_equiv.put (dead_ssa, *d);
-	  return (*d != NULL_TREE);
+	  tree d = *m_dead_ssa_debug_equiv.get (gimple_assign_rhs1 (def));
+	  gcc_assert (d);
+	  m_dead_ssa_debug_equiv.put (dead_ssa, d);
+	  return true;
 	}
 
       tree val


                 reply	other threads:[~2021-11-30 14:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20211130143648.1E9AD3858408@sourceware.org \
    --to=jamborm@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).