From 99873cb2d20f2091009d8fac935437eb6d122862 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223998 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/TableGen/Record.h | 2 +- lib/TableGen/TGParser.cpp | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h index a06f3c9f72c..4abeddd6be2 100644 --- a/include/llvm/TableGen/Record.h +++ b/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/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index 13feae03c48..a438cb6fc8f 100644 --- a/lib/TableGen/TGParser.cpp +++ b/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, -- 2.34.1