[Hexagon] Allocate MCInst in the MCContext to avoid leaking it.
[oota-llvm.git] / lib / Target / Hexagon / MCTargetDesc / HexagonMCInstrInfo.cpp
index 2940612080344e407f6746d3f2ce32ed499da7a6..2145fb7f4234501fc9551f17c4017efbcd623d8b 100644 (file)
@@ -28,7 +28,8 @@ void HexagonMCInstrInfo::addConstant(MCInst &MI, uint64_t Value,
   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::addConstExtender(MCInstrInfo const &MCII, MCInst &MCB,
 
   // 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::extenderForIndex(MCInst const &MCB,
   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