[llvm-commits] [llvm-gcc-4.0] r45981 - /llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp

Chris Lattner sabre at nondot.org
Mon Jan 14 14:34:07 PST 2008


Author: lattner
Date: Mon Jan 14 16:34:07 2008
New Revision: 45981

URL: http://llvm.org/viewvc/llvm-project?rev=45981&view=rev
Log:
Support a global that turns into a function.  This is the llvm-gcc 4.0 version of the 4.2 fix for PR1869

Modified:
    llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp

Modified: llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp?rev=45981&r1=45980&r2=45981&view=diff

==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp Mon Jan 14 16:34:07 2008
@@ -1032,7 +1032,26 @@
           FnEntry->setVisibility(GlobalValue::ProtectedVisibility);
       }
 
-      assert(FnEntry->getName() == Name &&"Preexisting fn with the same name!");
+      // If FnEntry got renamed, then there is already an object with this name
+      // in the symbol table.  If this happens, the old one must be a forward
+      // decl, just replace it with a cast of the new one.
+      if (FnEntry->getName() != Name) {
+        GlobalVariable *G = TheModule->getGlobalVariable(Name, true);
+        assert(G && G->isDeclaration() && "A global turned into a function?");
+        
+        // Replace any uses of "G" with uses of FnEntry.
+        Value *GInNewType = ConstantExpr::getBitCast(FnEntry, G->getType());
+        G->replaceAllUsesWith(GInNewType);
+        
+        // Update the decl that points to G.
+        changeLLVMValue(G, GInNewType);
+        
+        // Now we can give GV the proper name.
+        FnEntry->takeName(G);
+        
+        // G is now dead, nuke it.
+        G->eraseFromParent();
+      }
     }
     SET_DECL_LLVM(decl, FnEntry);
   } else {





More information about the llvm-commits mailing list