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

            Bug ID: 128365
           Summary: gimple-predicate-analysis.cc: simplify_2 leaks b_chain
                    on ordered_remove
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yansendao at 126 dot com
  Target Milestone: ---

predicate::simplify_2 in gcc/gimple-predicate-analysis.cc, when it finds
two equal chains that differ in exactly one negated predicate, removes
the negated predicate from a_chain and drops b_chain from m_preds:

      a_chain.ordered_remove (neg_idx);
      m_preds.ordered_remove (j);

b_chain (m_preds[j]) is a pred_chain, i.e. vec<pred_info, va_heap, vl_ptr>,
whose storage is heap-allocated.  m_preds.ordered_remove (j) drops the
element without releasing that storage, so every hit of this
simplification leaks the b_chain allocation.  simplify_2 runs during the
-Wuninitialized / -Wmaybe-uninitialized analysis, so the leak fires on
essentially every compile that reaches it.

Trivial fix: release the chain before removing it.

      a_chain.ordered_remove (neg_idx);
      b_chain.release ();
      m_preds.ordered_remove (j);

Pre-existing and unrelated to PR128102; spotted by Sashiko (VF3) while
reviewing that PR's series.

Reply via email to