https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99951

            Bug ID: 99951
           Summary: Dead return value after modify_call() is not released
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fxue at os dot amperecomputing.com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

By ipa_param_adjustments::modify_call(), a call statement with return value
might be replaced to a new void-return call. But the original return value SSA
is not released, which would give us garbage SSA when traversing
FOR_EACH_SSA_NAME.

In the following code, all uses of stmt's lhs are redirected to a new one, and
it becomes unused, but is never released from SSA name table.

  if (tree lhs = gimple_call_lhs (stmt))
    {
      if (!m_skip_return)
        gimple_call_set_lhs (new_stmt, lhs);
      else if (TREE_CODE (lhs) == SSA_NAME)
        {
          /* LHS should now by a default-def SSA.  Unfortunately default-def
             SSA_NAMEs need a backing variable (or at least some code examining
             SSAs assumes it is non-NULL).  So we either have to re-use the
             decl we have at hand or introdice a new one.  */
          tree repl = create_tmp_var (TREE_TYPE (lhs), "removed_return");
          repl = get_or_create_ssa_default_def (cfun, repl);
          SSA_NAME_IS_DEFAULT_DEF (repl) = true;
          imm_use_iterator ui;
          use_operand_p use_p;
          gimple *using_stmt;
          FOR_EACH_IMM_USE_STMT (using_stmt, ui, lhs)
            {
              FOR_EACH_IMM_USE_ON_STMT (use_p, ui)
                {
                  SET_USE (use_p, repl);
                }
              update_stmt (using_stmt);
            }
        }
    }

Reply via email to