[llvm] r252931 - [Hexagon] Allocate MCInst in the MCContext to avoid leaking it.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 12 11:30:41 PST 2015


Author: d0k
Date: Thu Nov 12 13:30:40 2015
New Revision: 252931

URL: http://llvm.org/viewvc/llvm-project?rev=252931&view=rev
Log:
[Hexagon] Allocate MCInst in the MCContext to avoid leaking it.

Found by leaksanitizer.

Modified:
    llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp
    llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp
    llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h

Modified: llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp?rev=252931&r1=252930&r2=252931&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/AsmParser/HexagonAsmParser.cpp Thu Nov 12 13:30:40 2015
@@ -871,7 +871,7 @@ bool HexagonAsmParser::MatchAndEmitInstr
                           MatchingInlineAsm, MustExtend))
     return true;
   HexagonMCInstrInfo::extendIfNeeded(
-      MCII, MCB, *SubInst,
+      getParser().getContext(), MCII, MCB, *SubInst,
       HexagonMCInstrInfo::isExtended(MCII, *SubInst) || MustExtend);
   MCB.addOperand(MCOperand::createInst(SubInst));
   if (!InBrackets)

Modified: llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp?rev=252931&r1=252930&r2=252931&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp Thu Nov 12 13:30:40 2015
@@ -28,7 +28,8 @@ void HexagonMCInstrInfo::addConstant(MCI
   MI.addOperand(MCOperand::createExpr(MCConstantExpr::create(Value, Context)));
 }
 
-void HexagonMCInstrInfo::addConstExtender(MCInstrInfo const &MCII, MCInst &MCB,
+void HexagonMCInstrInfo::addConstExtender(MCContext &Context,
+                                          MCInstrInfo const &MCII, MCInst &MCB,
                                           MCInst const &MCI) {
   assert(HexagonMCInstrInfo::isBundle(MCB));
   MCOperand const &exOp =
@@ -36,7 +37,7 @@ void HexagonMCInstrInfo::addConstExtende
 
   // Create the extender.
   MCInst *XMCI =
-      new MCInst(HexagonMCInstrInfo::deriveExtender(MCII, MCI, exOp));
+      new (Context) MCInst(HexagonMCInstrInfo::deriveExtender(MCII, MCI, exOp));
 
   MCB.addOperand(MCOperand::createInst(XMCI));
 }
@@ -150,10 +151,11 @@ MCInst const *HexagonMCInstrInfo::extend
   return nullptr;
 }
 
-void HexagonMCInstrInfo::extendIfNeeded(MCInstrInfo const &MCII, MCInst &MCB,
+void HexagonMCInstrInfo::extendIfNeeded(MCContext &Context,
+                                        MCInstrInfo const &MCII, MCInst &MCB,
                                         MCInst const &MCI, bool MustExtend) {
   if (isConstExtended(MCII, MCI) || MustExtend)
-    addConstExtender(MCII, MCB, MCI);
+    addConstExtender(Context, MCII, MCB, MCI);
 }
 
 HexagonII::MemAccessSize

Modified: llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h?rev=252931&r1=252930&r2=252931&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h (original)
+++ llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h Thu Nov 12 13:30:40 2015
@@ -53,7 +53,8 @@ int64_t const memStoreReorderEnabledMask
 size_t const bundleInstructionsOffset = 1;
 
 void addConstant(MCInst &MI, uint64_t Value, MCContext &Context);
-void addConstExtender(MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI);
+void addConstExtender(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB,
+                      MCInst const &MCI);
 
 // Returns a iterator range of instructions in this bundle
 iterator_range<MCInst::const_iterator> bundleInstructions(MCInst const &MCI);
@@ -71,8 +72,8 @@ void clampExtended(MCInstrInfo const &MC
 
 // Return the extender for instruction at Index or nullptr if none
 MCInst const *extenderForIndex(MCInst const &MCB, size_t Index);
-void extendIfNeeded(MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI,
-                    bool MustExtend);
+void extendIfNeeded(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB,
+                    MCInst const &MCI, bool MustExtend);
 
 // Create a duplex instruction given the two subinsts
 MCInst *deriveDuplex(MCContext &Context, unsigned iClass, MCInst const &inst0,




More information about the llvm-commits mailing list