https://gcc.gnu.org/g:6cecf3235b239bb854e6f90e515196c2a0785cd3

commit r17-6081-g6cecf3235b239bb854e6f90e515196c2a0785cd3
Author: Bohan Lei <[email protected]>
Date:   Mon Nov 9 11:22:54 2026 +0800

    RISC-V: Fix memory leak in permconst pass
    
    This patch fixes a memory leak in vector_permconst pass.  The memory
    leak was found during an LLM review of the codebase.
    
    Regtested on rv64gcv and rv32gcv.
    
    Assisted-by: Codex
    
    gcc/ChangeLog:
    
            * config/riscv/riscv-vect-permconst.cc (struct const_vector_hasher):
            Derive from free_ptr_hash.
            (vector_permconst::process_bb): Change vector_permconst_table to
            automatic variable.

Diff:
---
 gcc/config/riscv/riscv-vect-permconst.cc | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/gcc/config/riscv/riscv-vect-permconst.cc 
b/gcc/config/riscv/riscv-vect-permconst.cc
index 9692b47960b8..93120ecfcc69 100644
--- a/gcc/config/riscv/riscv-vect-permconst.cc
+++ b/gcc/config/riscv/riscv-vect-permconst.cc
@@ -90,7 +90,7 @@ struct vector_permconst_entry
   HOST_WIDE_INT bias;
 };
 
-struct const_vector_hasher : nofree_ptr_hash <vector_permconst_entry>
+struct const_vector_hasher : free_ptr_hash <vector_permconst_entry>
 {
   static inline hashval_t hash (const vector_permconst_entry *);
   static inline bool equal (const vector_permconst_entry *,
@@ -146,14 +146,13 @@ public:
 
 private:
   void process_bb (basic_block);
-  hash_table<const_vector_hasher> *vector_permconst_table;
 }; // class pass_vector_permconst
 
 /* Try to optimize vector permutation constants in BB.  */
 void
 vector_permconst::process_bb (basic_block bb)
 {
-  vector_permconst_table = new hash_table<const_vector_hasher> (11);
+  hash_table<const_vector_hasher> vector_permconst_table (11);
 
   /* Walk the insns in BB searching for vector loads from the constant pool
      which can be satisfied by adjusting an earlier load with trivial
@@ -239,7 +238,7 @@ vector_permconst::process_bb (basic_block bb)
       struct vector_permconst_entry tmp;
       tmp.normalized_vec = copy;
       struct vector_permconst_entry **slot
-       = vector_permconst_table->find_slot (&tmp, INSERT);
+       = vector_permconst_table.find_slot (&tmp, INSERT);
       if (*slot == NULL)
        {
          /* This constant was not in the table, so initialize the hash table
@@ -291,10 +290,6 @@ vector_permconst::process_bb (basic_block bb)
          (*slot)->insn = insn;
        }
     }
-
-  /* We construct and tear down the table for each block.  This may
-     be overly expensive.  */
-  vector_permconst_table->empty ();
 }
 
 /* Main entry point for this pass.  */

Reply via email to