Don't pollute the namespace with template arguments after they have been resolved


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7410 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/FileParser.y b/utils/TableGen/FileParser.y
index 6ebcf76..f8fa16d 100644
--- a/utils/TableGen/FileParser.y
+++ b/utils/TableGen/FileParser.y
@@ -409,9 +409,9 @@
          } OptTemplateArgList ClassList {
            for (unsigned i = 0, e = $4->size(); i != e; ++i) {
 	     addSubClass((*$4)[i].first, *(*$4)[i].second);
-	     delete (*$4)[i].second;  // Delete the template list
-	   }
-           delete $4;
+             // Delete the template arg values for the class
+             delete (*$4)[i].second;
+           }
 
 	   // Process any variables on the set stack...
 	   for (unsigned i = 0, e = SetStack.size(); i != e; ++i)
@@ -419,6 +419,17 @@
 		      SetStack[i].second);
          } Body {
   CurRec->resolveReferences();
+
+  // Now that all of the references have been resolved, we can delete template
+  // arguments for superclasses, so they don't pollute our record, and so that
+  // their names won't conflict with later uses of the name...
+  for (unsigned i = 0, e = $4->size(); i != e; ++i) {
+    Record *SuperClass = (*$4)[i].first;
+    for (unsigned i = 0, e = SuperClass->getTemplateArgs().size(); i != e; ++i)
+    CurRec->removeValue(SuperClass->getTemplateArgs()[i]);
+  }
+  delete $4;   // Delete the class list...
+
   $$ = CurRec;
   CurRec = 0;
 };