Fix PR918 by only using typedefs to name struct types. This makes the later
authorChris Lattner <sabre@nondot.org>
Tue, 16 Jan 2007 07:22:23 +0000 (07:22 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 16 Jan 2007 07:22:23 +0000 (07:22 +0000)
type ordering stuff work better.  This fixes PR918 and
CodeGen/CBackend/2007-01-15-NamedArrayType.ll

Patch by Gordon Henriksen.

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

lib/Target/CBackend/CBackend.cpp

index 8a6a0a9df2352483e8fe14f6c8b44d83f3f4cf27..304145887b0ffa45ecebd43e32740590d696dc87 100644 (file)
@@ -269,13 +269,19 @@ bool CBackendNameAllUsedStructsAndMergeFunctions::runOnModule(Module &M) {
   for (TypeSymbolTable::iterator TI = TST.begin(), TE = TST.end();
        TI != TE; ) {
     TypeSymbolTable::iterator I = TI++;
   for (TypeSymbolTable::iterator TI = TST.begin(), TE = TST.end();
        TI != TE; ) {
     TypeSymbolTable::iterator I = TI++;
-
-    // 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())
+    
+    // If this isn't a struct type, remove it from our set of types to name.
+    // This simplifies emission later.
+    if (!isa<StructType>(I->second)) {
       TST.remove(I);
       TST.remove(I);
-    else
-      UT.erase(UTI);    // Only keep one name for this type.
+    } else {
+      // 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())
+        TST.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
   }
 
   // UT now contains types that are not named.  Loop over it, naming
@@ -1694,10 +1700,11 @@ void CWriter::printModuleTypes(const TypeSymbolTable &TST) {
 
   Out << '\n';
 
 
   Out << '\n';
 
-  // Now we can print out typedefs...
+  // Now we can print out typedefs.  Above, we guaranteed that this can only be
+  // for struct types.
   Out << "/* Typedefs */\n";
   for (I = TST.begin(); I != End; ++I) {
   Out << "/* Typedefs */\n";
   for (I = TST.begin(); I != End; ++I) {
-    const Type *Ty = cast<Type>(I->second);
+    const StructType *Ty = cast<StructType>(I->second);
     std::string Name = "l_" + Mang->makeNameProper(I->first);
     Out << "typedef ";
     printType(Out, Ty, false, Name);
     std::string Name = "l_" + Mang->makeNameProper(I->first);
     Out << "typedef ";
     printType(Out, Ty, false, Name);