From c3504c48748c0c8fc2d6ccbd79f776766fedf967 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 11 Dec 2014 05:25:33 +0000 Subject: [PATCH] Make MultiClass::DefPrototypes own their Records to fix memory leaks. llvm-svn: 223998 --- llvm/include/llvm/TableGen/Record.h | 2 +- llvm/lib/TableGen/TGParser.cpp | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index a06f3c9f72c4..4abeddd6be29 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -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 RecordVector; + typedef std::vector> RecordVector; RecordVector DefPrototypes; void dump() const; diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 13feae03c48d..a438cb6fc8f2 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -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 &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(), 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 &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(CurRec)); // Copy the template arguments for the multiclass into the new def. const std::vector &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,