From 50083146f072b5f2bb6f614c2000b7244168101e Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 11 Dec 2014 05:25:30 +0000 Subject: [PATCH] Replace std::map with std::map> to handle ownership and deletion of the values. Ideally we would store the MultiClasses by value directly in the maps, but I had some trouble with that before and this at least fixes the leak. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223997 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/TGParser.cpp | 13 ++++++++----- lib/TableGen/TGParser.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index 4b7ccdca9b1..13feae03c48 100644 --- a/lib/TableGen/TGParser.cpp +++ b/lib/TableGen/TGParser.cpp @@ -459,7 +459,7 @@ MultiClass *TGParser::ParseMultiClassID() { return nullptr; } - MultiClass *Result = MultiClasses[Lex.getCurStrVal()]; + MultiClass *Result = MultiClasses[Lex.getCurStrVal()].get(); if (!Result) TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'"); @@ -2290,11 +2290,14 @@ bool TGParser::ParseMultiClass() { return TokError("expected identifier after multiclass for name"); std::string Name = Lex.getCurStrVal(); - if (MultiClasses.count(Name)) + auto Result = + MultiClasses.insert(std::make_pair(Name, + llvm::make_unique(Name, Lex.getLoc(),Records))); + + if (!Result.second) return TokError("multiclass '" + Name + "' already defined"); - CurMultiClass = MultiClasses[Name] = new MultiClass(Name, - Lex.getLoc(), Records); + CurMultiClass = Result.first->second.get(); Lex.Lex(); // Eat the identifier. // If there are template args, parse them. @@ -2555,7 +2558,7 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) { // To instantiate a multiclass, we need to first get the multiclass, then // instantiate each def contained in the multiclass with the SubClassRef // template parameters. - MultiClass *MC = MultiClasses[Ref.Rec->getName()]; + MultiClass *MC = MultiClasses[Ref.Rec->getName()].get(); assert(MC && "Didn't lookup multiclass correctly?"); std::vector &TemplateVals = Ref.TemplateArgs; diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h index 79994cbc1a6..22a00e59195 100644 --- a/lib/TableGen/TGParser.h +++ b/lib/TableGen/TGParser.h @@ -55,7 +55,7 @@ namespace llvm { class TGParser { TGLexer Lex; std::vector > LetStack; - std::map MultiClasses; + std::map> MultiClasses; /// Loops - Keep track of any foreach loops we are within. ///