[llvm] [MIR] Fix vreg flag vector memory leak (PR #112479)

Akshat Oke via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 15 22:03:21 PDT 2024


https://github.com/optimisan created https://github.com/llvm/llvm-project/pull/112479

A fix-it patch for bec839d8eed9dd13fa7eaffd50b28f8f913de2e2 #110229.

`SmallVector` will inline 40 values (here) statically on the stack. Although once that is exhausted it'll heap allocate and won't be deallocated.

The virtual register flags vector had a memory leak because the vector's memory is not freed.
The `BumpPtrAllocator` handles the deallocation and misses calling the `std::vector<uint8_t> Flags` destructor.


>From 66518e9f6642246da0261dc052c1caf934730fc1 Mon Sep 17 00:00:00 2001
From: Akshat Oke <Akshat.Oke at amd.com>
Date: Tue, 15 Oct 2024 16:49:32 +0000
Subject: [PATCH] [MIR] Fix vreg flag vector memory leak

SmallVector allocates on stack so that works out here.
---
 llvm/include/llvm/CodeGen/MIRParser/MIParser.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/CodeGen/MIRParser/MIParser.h b/llvm/include/llvm/CodeGen/MIRParser/MIParser.h
index 4d93213de5e070..ea4ba488c9295b 100644
--- a/llvm/include/llvm/CodeGen/MIRParser/MIParser.h
+++ b/llvm/include/llvm/CodeGen/MIRParser/MIParser.h
@@ -45,7 +45,7 @@ struct VRegInfo {
   } D;
   Register VReg;
   Register PreferredReg;
-  std::vector<uint8_t> Flags;
+  SmallVector<uint8_t> Flags;
 };
 
 using Name2RegClassMap = StringMap<const TargetRegisterClass *>;



More information about the llvm-commits mailing list