From: Craig Topper Date: Sun, 30 Nov 2014 01:20:17 +0000 (+0000) Subject: Revert r222957 "Replace std::map with std::map to handle ownership and... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=73642a847d9c254140030d0a803f610967b81f9e;p=oota-llvm.git Revert r222957 "Replace std::map with std::map to handle ownership and deletion of the values." Upon further review I think the MultiClass is being copied into the map instead of being moved due to the copy constructor on the nested Record type. This ultimately got exposed when the vector in DefPrototype vector was changed to hold unique_ptrs in another commit. This caused gcc 4.7 to fail due to the use of the copy constructor on unique_ptr with the error pointing back to one of the insert calls from this commit. Not sure why clang was able to build. This reverts commit 710cdf729f84b428bf41aa8d32dbdb35fff79fde. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222971 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index b227de88896..4b7ccdca9b1 100644 --- a/lib/TableGen/TGParser.cpp +++ b/lib/TableGen/TGParser.cpp @@ -459,12 +459,12 @@ MultiClass *TGParser::ParseMultiClassID() { return nullptr; } - auto it = MultiClasses.find(Lex.getCurStrVal()); - if (it == MultiClasses.end()) + MultiClass *Result = MultiClasses[Lex.getCurStrVal()]; + if (!Result) TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'"); Lex.Lex(); - return &it->second; + return Result; } /// ParseSubClassReference - Parse a reference to a subclass or to a templated @@ -2290,13 +2290,11 @@ bool TGParser::ParseMultiClass() { return TokError("expected identifier after multiclass for name"); std::string Name = Lex.getCurStrVal(); - auto Result = - MultiClasses.insert(std::make_pair(Name, - MultiClass(Name, Lex.getLoc(),Records))); - if (!Result.second) + if (MultiClasses.count(Name)) return TokError("multiclass '" + Name + "' already defined"); - CurMultiClass = &Result.first->second; + CurMultiClass = MultiClasses[Name] = new MultiClass(Name, + Lex.getLoc(), Records); Lex.Lex(); // Eat the identifier. // If there are template args, parse them. @@ -2557,9 +2555,8 @@ 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. - auto it = MultiClasses.find(Ref.Rec->getName()); - assert(it != MultiClasses.end() && "Didn't lookup multiclass correctly?"); - MultiClass *MC = &it->second; + MultiClass *MC = MultiClasses[Ref.Rec->getName()]; + assert(MC && "Didn't lookup multiclass correctly?"); std::vector &TemplateVals = Ref.TemplateArgs; // Verify that the correct number of template arguments were specified. diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h index 45f418ab344..79994cbc1a6 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. ///