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

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 02:22:29 PDT 2024


Author: Akshat Oke
Date: 2024-10-16T14:52:25+05:30
New Revision: b5cc222d7429fe6f18c787f633d5262fac2e676f

URL: https://github.com/llvm/llvm-project/commit/b5cc222d7429fe6f18c787f633d5262fac2e676f
DIFF: https://github.com/llvm/llvm-project/commit/b5cc222d7429fe6f18c787f633d5262fac2e676f.diff

LOG: [MIR] Fix vreg flag vector memory leak (#112479)

A fix-it patch for dbfca24 #110228.

No need for a container. This allows 8 flags for a register.

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

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/MIRParser/MIParser.h
    llvm/lib/CodeGen/MIRParser/MIRParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/MIRParser/MIParser.h b/llvm/include/llvm/CodeGen/MIRParser/MIParser.h
index 4d93213de5e070..0f2898d3554d06 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;
+  uint8_t Flags = 0;
 };
 
 using Name2RegClassMap = StringMap<const TargetRegisterClass *>;

diff  --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index 10d3cdcf0c1ce1..c0c61b3fdd1677 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -703,7 +703,7 @@ bool MIRParserImpl::parseRegisterInfo(PerFunctionMIParsingState &PFS,
         return error(FlagStringValue.SourceRange.Start,
                      Twine("use of undefined register flag '") +
                          FlagStringValue.Value + "'");
-      Info.Flags.push_back(FlagValue);
+      Info.Flags |= FlagValue;
     }
     RegInfo.noteNewVirtualRegister(Info.VReg);
   }


        


More information about the llvm-commits mailing list