llvm.org GIT mirror llvm / 99873cb
Make MultiClass::DefPrototypes own their Records to fix memory leaks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223998 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 5 years ago
2 changed file(s) with 9 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
16621662
16631663 struct MultiClass {
16641664 Record Rec; // Placeholder for template args and Name.
1665 typedef std::vector<Record*> RecordVector;
1665 typedef std::vector<std::unique_ptr> RecordVector;
16661666 RecordVector DefPrototypes;
16671667
16681668 void dump() const;
238238 if (AddValue(NewDef.get(), SubMultiClass.RefRange.Start, MCVals[i]))
239239 return true;
240240
241 CurMC->DefPrototypes.push_back(NewDef.release());
241 CurMC->DefPrototypes.push_back(std::move(NewDef));
242242 }
243243
244244 const std::vector &SMCTArgs = SMC->Rec.getTemplateArgs();
268268
269269 // If a value is specified for this template arg, set it in the
270270 // new defs now.
271 for (MultiClass::RecordVector::iterator j =
272 CurMC->DefPrototypes.begin() + newDefStart,
273 jend = CurMC->DefPrototypes.end();
274 j != jend;
275 ++j) {
276 Record *Def = *j;
277
278 if (SetValue(Def, SubMultiClass.RefRange.Start, SMCTArgs[i],
271 for (const auto &Def :
272 makeArrayRef(CurMC->DefPrototypes).slice(newDefStart)) {
273 if (SetValue(Def.get(), SubMultiClass.RefRange.Start, SMCTArgs[i],
279274 std::vector(),
280275 SubMultiClass.TemplateArgs[i]))
281276 return true;
12571252 // known before any use.
12581253 NewRec->setResolveFirst(true);
12591254 // Otherwise, we're inside a multiclass, add it to the multiclass.
1260 CurMultiClass->DefPrototypes.push_back(NewRecOwner.release());
1255 CurMultiClass->DefPrototypes.push_back(std::move(NewRecOwner));
12611256
12621257 // Copy the template arguments for the multiclass into the def.
12631258 const std::vector &TArgs =
20622057 == CurRec->getNameInit())
20632058 return Error(DefLoc, "def '" + CurRec->getNameInitAsString() +
20642059 "' already defined in this multiclass!");
2065 CurMultiClass->DefPrototypes.push_back(CurRecOwner.release());
2060 CurMultiClass->DefPrototypes.push_back(std::move(CurRecOwner));
20662061 } else if (ParseObjectBody(CurRec)) {
20672062 return true;
20682063 }
25072502 == CurRec->getNameInit())
25082503 return Error(DefmPrefixLoc, "defm '" + CurRec->getNameInitAsString() +
25092504 "' already defined in this multiclass!");
2510 CurMultiClass->DefPrototypes.push_back(CurRec);
2505 CurMultiClass->DefPrototypes.push_back(std::unique_ptr(CurRec));
25112506
25122507 // Copy the template arguments for the multiclass into the new def.
25132508 const std::vector &TA =
25692564
25702565 // Loop over all the def's in the multiclass, instantiating each one.
25712566 for (unsigned i = 0, e = MC->DefPrototypes.size(); i != e; ++i) {
2572 Record *DefProto = MC->DefPrototypes[i];
2567 Record *DefProto = MC->DefPrototypes[i].get();
25732568
25742569 Record *CurRec = InstantiateMulticlassDef(*MC, DefProto, DefmPrefix,
25752570 SMRange(DefmLoc,