Make MultiClass::DefPrototypes own their Records to fix memory leaks.

llvm-svn: 223998
This commit is contained in:
Craig Topper 2014-12-11 05:25:33 +00:00
parent 7adf2bf76a
commit c3504c4874
2 changed files with 9 additions and 14 deletions

View File

@ -1663,7 +1663,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Record &R);
struct MultiClass {
Record Rec; // Placeholder for template args and Name.
typedef std::vector<Record*> RecordVector;
typedef std::vector<std::unique_ptr<Record>> RecordVector;
RecordVector DefPrototypes;
void dump() const;

View File

@ -239,7 +239,7 @@ bool TGParser::AddSubMultiClass(MultiClass *CurMC,
if (AddValue(NewDef.get(), SubMultiClass.RefRange.Start, MCVals[i]))
return true;
CurMC->DefPrototypes.push_back(NewDef.release());
CurMC->DefPrototypes.push_back(std::move(NewDef));
}
const std::vector<Init *> &SMCTArgs = SMC->Rec.getTemplateArgs();
@ -269,14 +269,9 @@ bool TGParser::AddSubMultiClass(MultiClass *CurMC,
// If a value is specified for this template arg, set it in the
// new defs now.
for (MultiClass::RecordVector::iterator j =
CurMC->DefPrototypes.begin() + newDefStart,
jend = CurMC->DefPrototypes.end();
j != jend;
++j) {
Record *Def = *j;
if (SetValue(Def, SubMultiClass.RefRange.Start, SMCTArgs[i],
for (const auto &Def :
makeArrayRef(CurMC->DefPrototypes).slice(newDefStart)) {
if (SetValue(Def.get(), SubMultiClass.RefRange.Start, SMCTArgs[i],
std::vector<unsigned>(),
SubMultiClass.TemplateArgs[i]))
return true;
@ -1258,7 +1253,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
// known before any use.
NewRec->setResolveFirst(true);
// Otherwise, we're inside a multiclass, add it to the multiclass.
CurMultiClass->DefPrototypes.push_back(NewRecOwner.release());
CurMultiClass->DefPrototypes.push_back(std::move(NewRecOwner));
// Copy the template arguments for the multiclass into the def.
const std::vector<Init *> &TArgs =
@ -2063,7 +2058,7 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) {
== CurRec->getNameInit())
return Error(DefLoc, "def '" + CurRec->getNameInitAsString() +
"' already defined in this multiclass!");
CurMultiClass->DefPrototypes.push_back(CurRecOwner.release());
CurMultiClass->DefPrototypes.push_back(std::move(CurRecOwner));
} else if (ParseObjectBody(CurRec)) {
return true;
}
@ -2508,7 +2503,7 @@ bool TGParser::ResolveMulticlassDef(MultiClass &MC,
== CurRec->getNameInit())
return Error(DefmPrefixLoc, "defm '" + CurRec->getNameInitAsString() +
"' already defined in this multiclass!");
CurMultiClass->DefPrototypes.push_back(CurRec);
CurMultiClass->DefPrototypes.push_back(std::unique_ptr<Record>(CurRec));
// Copy the template arguments for the multiclass into the new def.
const std::vector<Init *> &TA =
@ -2570,7 +2565,7 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) {
// Loop over all the def's in the multiclass, instantiating each one.
for (unsigned i = 0, e = MC->DefPrototypes.size(); i != e; ++i) {
Record *DefProto = MC->DefPrototypes[i];
Record *DefProto = MC->DefPrototypes[i].get();
Record *CurRec = InstantiateMulticlassDef(*MC, DefProto, DefmPrefix,
SMRange(DefmLoc,