]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa-param-manip: Be careful about a reallocating hash_map
authorMartin Jambor <mjambor@suse.cz>
Tue, 30 Nov 2021 14:35:18 +0000 (15:35 +0100)
committerMartin Jambor <mjambor@suse.cz>
Tue, 30 Nov 2021 14:35:47 +0000 (15:35 +0100)
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.

gcc/ipa-param-manipulation.c

index 479c20b3871e71cf6310266d77efbc245d0ba93d..163af94cde0fca127ce162689e81151985337d8a 100644 (file)
@@ -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