[llvm-commits] [llvm-gcc-4.2] r45979 - /llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
Chris Lattner
sabre at nondot.org
Mon Jan 14 14:27:53 PST 2008
Author: lattner
Date: Mon Jan 14 16:27:52 2008
New Revision: 45979
URL: http://llvm.org/viewvc/llvm-project?rev=45979&view=rev
Log:
Fix test/C++Frontend/2007-03-27-FunctionVarRename.cpp with llvm-g++ 4.2,
which is PR1869. This bug actually occurs in 4.0 as well, but 4.2 gets
unlucky and processes things in a different order.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=45979&r1=45978&r2=45979&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Mon Jan 14 16:27:52 2008
@@ -1102,7 +1102,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