Revert r222957 "Replace std::map<K, V*> with std::map<K, V> to handle ownership and...
authorCraig Topper <craig.topper@gmail.com>
Sun, 30 Nov 2014 01:20:17 +0000 (01:20 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sun, 30 Nov 2014 01:20:17 +0000 (01:20 +0000)
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

lib/TableGen/TGParser.cpp
lib/TableGen/TGParser.h

index b227de888968dac3b6f9151fe056af4cfa5644cb..4b7ccdca9b19eb0286b40a1e22e8d4ff8a648042 100644 (file)
@@ -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<Init*> &TemplateVals = Ref.TemplateArgs;
 
     // Verify that the correct number of template arguments were specified.
index 45f418ab344e45936f514863315cba610b9fcc10..79994cbc1a6dbf2b8ee38f5480c0c728444b8a9a 100644 (file)
@@ -55,7 +55,7 @@ namespace llvm {
 class TGParser {
   TGLexer Lex;
   std::vector<std::vector<LetRecord> > LetStack;
-  std::map<std::string, MultiClass> MultiClasses;
+  std::map<std::string, MultiClass*> MultiClasses;
 
   /// Loops - Keep track of any foreach loops we are within.
   ///