Make sure to remove all dead type names from the symbol table, not just
authorChris Lattner <sabre@nondot.org>
Tue, 8 Mar 2005 16:19:59 +0000 (16:19 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 8 Mar 2005 16:19:59 +0000 (16:19 +0000)
struct types.  This fixes Regression/CodeGen/CBackend/2005-03-08-RecursiveTypeCrash.ll,
a crash on Java output that Alkis reported.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20519 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp

index 57de4e5f770aa5474d4476f0c41e54c0fd496ec6..111468f023752ae3201656aeff9257a2983460db 100644 (file)
@@ -227,20 +227,19 @@ bool CBackendNameAllUsedStructs::runOnModule(Module &M) {
   std::set<const Type *> UT = getAnalysis<FindUsedTypes>().getTypes();
   
   // Loop over the module symbol table, removing types from UT that are
-  // already named, and removing names for structure types that are not used.
+  // already named, and removing names for types that are not used.
   //
   SymbolTable &MST = M.getSymbolTable();
   for (SymbolTable::type_iterator TI = MST.type_begin(), TE = MST.type_end();
        TI != TE; ) {
     SymbolTable::type_iterator I = TI++;
-    if (const StructType *STy = dyn_cast<StructType>(I->second)) {
-      // If this is not used, remove it from the symbol table.
-      std::set<const Type *>::iterator UTI = UT.find(STy);
-      if (UTI == UT.end())
-        MST.remove(I);
-      else
-        UT.erase(UTI);
-    }
+
+    // If this is not used, remove it from the symbol table.
+    std::set<const Type *>::iterator UTI = UT.find(I->second);
+    if (UTI == UT.end())
+      MST.remove(I);
+    else
+      UT.erase(UTI);    // Only keep one name for this type.
   }
 
   // UT now contains types that are not named.  Loop over it, naming
index 57de4e5f770aa5474d4476f0c41e54c0fd496ec6..111468f023752ae3201656aeff9257a2983460db 100644 (file)
@@ -227,20 +227,19 @@ bool CBackendNameAllUsedStructs::runOnModule(Module &M) {
   std::set<const Type *> UT = getAnalysis<FindUsedTypes>().getTypes();
   
   // Loop over the module symbol table, removing types from UT that are
-  // already named, and removing names for structure types that are not used.
+  // already named, and removing names for types that are not used.
   //
   SymbolTable &MST = M.getSymbolTable();
   for (SymbolTable::type_iterator TI = MST.type_begin(), TE = MST.type_end();
        TI != TE; ) {
     SymbolTable::type_iterator I = TI++;
-    if (const StructType *STy = dyn_cast<StructType>(I->second)) {
-      // If this is not used, remove it from the symbol table.
-      std::set<const Type *>::iterator UTI = UT.find(STy);
-      if (UTI == UT.end())
-        MST.remove(I);
-      else
-        UT.erase(UTI);
-    }
+
+    // If this is not used, remove it from the symbol table.
+    std::set<const Type *>::iterator UTI = UT.find(I->second);
+    if (UTI == UT.end())
+      MST.remove(I);
+    else
+      UT.erase(UTI);    // Only keep one name for this type.
   }
 
   // UT now contains types that are not named.  Loop over it, naming