https://gcc.gnu.org/g:7b3a0f74e45fcc9a7626fe87e324b236086522a8

commit r16-5418-g7b3a0f74e45fcc9a7626fe87e324b236086522a8
Author: Richard Biener <[email protected]>
Date:   Wed Nov 19 11:27:43 2025 +0100

    Fix dr_chain memleak in vectorizable_load
    
    Figured while running a leak check on some new SLP code.
    
            * tree-vect-stmts.cc (vectorizable_load): Make dr_chain
            an auto_vec, move down to where we use it to avoid creating
            it twice.

Diff:
---
 gcc/tree-vect-stmts.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 07d476ac44f9..748b3bcb0ab0 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -9632,7 +9632,6 @@ vectorizable_load (vec_info *vinfo,
   tree msq = NULL_TREE, lsq;
   tree realignment_token = NULL_TREE;
   gphi *phi = NULL;
-  vec<tree> dr_chain = vNULL;
   bool grouped_load = false;
   stmt_vec_info first_stmt_info;
   stmt_vec_info first_stmt_info_for_drptr = NULL;
@@ -10428,7 +10427,6 @@ vectorizable_load (vec_info *vinfo,
        {
          group_gap_adj = group_size - scalar_lanes;
        }
-      dr_chain.create (vec_num);
 
       ref_type = get_group_alias_ptr_type (first_stmt_info);
     }
@@ -10764,6 +10762,8 @@ vectorizable_load (vec_info *vinfo,
     {
       gcc_assert ((!grouped_load && !ls.slp_perm) || ls.ls_type);
 
+      auto_vec<tree> dr_chain (vec_num);
+
       /* If we pun the original vectype the loads as well as costing, length,
         etc. is performed with the new type.  After loading we VIEW_CONVERT
         the data to the original vectype.  */
@@ -11261,6 +11261,7 @@ vectorizable_load (vec_info *vinfo,
                                       stmt_info, bump);
     }
 
+  auto_vec<tree> dr_chain;
   if (grouped_load || ls.slp_perm)
     dr_chain.create (vec_num);
 
@@ -11820,7 +11821,6 @@ vectorizable_load (vec_info *vinfo,
                                                  nullptr, true);
          gcc_assert (ok && ls.n_perms == n_perms2);
        }
-      dr_chain.release ();
     }
 
   if (costing_p)

Reply via email to