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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222965 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper 2014-11-30 00:19:28 +00:00
parent 809b955259
commit a1fa859a92
2 changed files with 7 additions and 7 deletions

View File

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

View File

@ -239,7 +239,7 @@ bool TGParser::AddSubMultiClass(MultiClass *CurMC,
if (AddValue(NewDef.get(), SubMultiClass.RefRange.Start, MCVals[i])) if (AddValue(NewDef.get(), SubMultiClass.RefRange.Start, MCVals[i]))
return true; return true;
CurMC->DefPrototypes.push_back(NewDef.release()); CurMC->DefPrototypes.push_back(std::move(NewDef));
} }
const std::vector<Init *> &SMCTArgs = SMC->Rec.getTemplateArgs(); const std::vector<Init *> &SMCTArgs = SMC->Rec.getTemplateArgs();
@ -274,7 +274,7 @@ bool TGParser::AddSubMultiClass(MultiClass *CurMC,
jend = CurMC->DefPrototypes.end(); jend = CurMC->DefPrototypes.end();
j != jend; j != jend;
++j) { ++j) {
Record *Def = *j; Record *Def = j->get();
if (SetValue(Def, SubMultiClass.RefRange.Start, SMCTArgs[i], if (SetValue(Def, SubMultiClass.RefRange.Start, SMCTArgs[i],
std::vector<unsigned>(), std::vector<unsigned>(),
@ -1258,7 +1258,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
// known before any use. // known before any use.
NewRec->setResolveFirst(true); NewRec->setResolveFirst(true);
// Otherwise, we're inside a multiclass, add it to the multiclass. // 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. // Copy the template arguments for the multiclass into the def.
const std::vector<Init *> &TArgs = const std::vector<Init *> &TArgs =
@ -2063,7 +2063,7 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) {
== CurRec->getNameInit()) == CurRec->getNameInit())
return Error(DefLoc, "def '" + CurRec->getNameInitAsString() + return Error(DefLoc, "def '" + CurRec->getNameInitAsString() +
"' already defined in this multiclass!"); "' already defined in this multiclass!");
CurMultiClass->DefPrototypes.push_back(CurRecOwner.release()); CurMultiClass->DefPrototypes.push_back(std::move(CurRecOwner));
} else if (ParseObjectBody(CurRec)) { } else if (ParseObjectBody(CurRec)) {
return true; return true;
} }
@ -2507,7 +2507,7 @@ bool TGParser::ResolveMulticlassDef(MultiClass &MC,
== CurRec->getNameInit()) == CurRec->getNameInit())
return Error(DefmPrefixLoc, "defm '" + CurRec->getNameInitAsString() + return Error(DefmPrefixLoc, "defm '" + CurRec->getNameInitAsString() +
"' already defined in this multiclass!"); "' 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. // Copy the template arguments for the multiclass into the new def.
const std::vector<Init *> &TA = const std::vector<Init *> &TA =
@ -2570,7 +2570,7 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) {
// Loop over all the def's in the multiclass, instantiating each one. // Loop over all the def's in the multiclass, instantiating each one.
for (unsigned i = 0, e = MC->DefPrototypes.size(); i != e; ++i) { 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, Record *CurRec = InstantiateMulticlassDef(*MC, DefProto, DefmPrefix,
SMRange(DefmLoc, SMRange(DefmLoc,