public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113476] New: [14 Regression] irange::maybe_resize leaks memory via IPA VRP
@ 2024-01-18 11:43 rguenth at gcc dot gnu.org
  2024-01-18 11:43 ` [Bug tree-optimization/113476] " rguenth at gcc dot gnu.org
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-18 11:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113476
           Summary: [14 Regression] irange::maybe_resize leaks memory via
                    IPA VRP
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

I see

==1854== 122,424 bytes in 3 blocks are possibly lost in loss record 1,365 of
1,373
==1854==    at 0x505A1DF: operator new[](unsigned long) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==1854==    by 0x1B8AB58: irange::maybe_resize(int) (value-range.h:645)
==1854==    by 0x1B7C7DF: irange::union_(vrange const&) (value-range.cc:1451)
==1854==    by 0x1B1D777: Value_Range::union_(vrange const&)
(value-range.h:705)
==1854==    by 0x30355A4: ipcp_vr_lattice::meet_with_1(vrange const&)
(ipa-cp.cc:1046)
==1854==    by 0x3035508: ipcp_vr_lattice::meet_with(vrange const&)
(ipa-cp.cc:1

where union_ does

  // At this point, the vector should have i ranges, none overlapping.
  // Now it simply needs to be copied, and if there are too many
  // ranges, merge some.  We wont do any analysis as to what the
  // "best" merges are, simply combine the final ranges into one.
  maybe_resize (i / 2);

and maybe_resize:

inline void
irange::maybe_resize (int needed)
{ 
  if (!m_resizable || m_max_ranges == HARD_MAX_RANGES)
    return;

  if (needed > m_max_ranges)
    {
      m_max_ranges = HARD_MAX_RANGES;
      wide_int *newmem = new wide_int[m_max_ranges * 2];
      unsigned n = num_pairs () * 2;
      for (unsigned i = 0; i < n; ++i)
        newmem[i] = m_base[i];
      m_base = newmem;
    }

that looks OK at first right but there's an irange CTOR

inline
irange::irange (wide_int *base, unsigned nranges, bool resizable)

that might end up with unexpected m_base/m_max_ranges here.

Testcase is dwarf2out.i preprocessed from the last release using C but I
guess it's easy to reproduce with any TU from GCC itself.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2024-02-22 16:07 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-18 11:43 [Bug tree-optimization/113476] New: [14 Regression] irange::maybe_resize leaks memory via IPA VRP rguenth at gcc dot gnu.org
2024-01-18 11:43 ` [Bug tree-optimization/113476] " rguenth at gcc dot gnu.org
2024-01-18 11:48 ` rguenth at gcc dot gnu.org
2024-01-18 11:50 ` rguenth at gcc dot gnu.org
2024-01-18 13:32 ` rguenth at gcc dot gnu.org
2024-01-22 17:48 ` jamborm at gcc dot gnu.org
2024-01-23  6:58 ` rguenth at gcc dot gnu.org
2024-02-19 15:05 ` jamborm at gcc dot gnu.org
2024-02-21  9:15 ` aldyh at gcc dot gnu.org
2024-02-21  9:17 ` aldyh at gcc dot gnu.org
2024-02-21  9:18 ` aldyh at gcc dot gnu.org
2024-02-21  9:19 ` aldyh at gcc dot gnu.org
2024-02-21 11:22 ` aldyh at gcc dot gnu.org
2024-02-21 11:25 ` jakub at gcc dot gnu.org
2024-02-21 11:55 ` aldyh at gcc dot gnu.org
2024-02-21 12:10 ` jakub at gcc dot gnu.org
2024-02-21 14:43 ` [Bug ipa/113476] " cvs-commit at gcc dot gnu.org
2024-02-21 14:44 ` jamborm at gcc dot gnu.org
2024-02-22  7:38 ` rguenther at suse dot de
2024-02-22 16:07 ` aldyh at gcc dot gnu.org

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).