summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-09 23:53:08 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-09 23:53:08 +0000
commit99d28350991851acf6721318e0f26b2eaa9efa26 (patch)
treeaf789b3268a17432cc88e93f1b4253aad291e16c /clang/lib/CodeGen/CodeGenModule.cpp
parentd9c90a73175750384c89921a69008ee95eb8b690 (diff)
downloadbcm5719-llvm-99d28350991851acf6721318e0f26b2eaa9efa26.tar.gz
bcm5719-llvm-99d28350991851acf6721318e0f26b2eaa9efa26.zip
Backout r66408, we don't want handling of globals to rely on the
module symbol table. The root problem inspiring this was fixed in r66316 (and again in r66506). llvm-svn: 66512
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp68
1 files changed, 32 insertions, 36 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 41784cbb813..16ba94791fa 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -788,8 +788,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
llvm::GlobalValue *
CodeGenModule::EmitForwardFunctionDefinition(const FunctionDecl *D,
- const llvm::Type *Ty,
- bool ReplaceExisting) {
+ const llvm::Type *Ty) {
bool DoSetAttributes = true;
if (!Ty) {
Ty = getTypes().ConvertType(D->getType());
@@ -802,13 +801,10 @@ CodeGenModule::EmitForwardFunctionDefinition(const FunctionDecl *D,
DoSetAttributes = false;
}
}
- const char *Name = getMangledName(D);
- llvm::Function *F = getModule().getFunction(Name);
- if (ReplaceExisting || !F || !F->hasExternalLinkage())
- F = llvm::Function::Create(cast<llvm::FunctionType>(Ty),
- llvm::Function::ExternalLinkage,
- Name,
- &getModule());
+ llvm::Function *F = llvm::Function::Create(cast<llvm::FunctionType>(Ty),
+ llvm::Function::ExternalLinkage,
+ getMangledName(D),
+ &getModule());
if (DoSetAttributes)
SetFunctionAttributes(D, F);
return F;
@@ -842,33 +838,33 @@ void CodeGenModule::EmitGlobalFunctionDefinition(const FunctionDecl *D) {
llvm::GlobalValue *&Entry = GlobalDeclMap[getMangledName(D)];
if (!Entry) {
Entry = EmitForwardFunctionDefinition(D, Ty);
- }
-
- // If the types mismatch then we have to rewrite the definition.
- if (Entry->getType() != llvm::PointerType::getUnqual(Ty)) {
- // Otherwise, we have a definition after a prototype with the
- // wrong type. F is the Function* for the one with the wrong
- // type, we must make a new Function* and update everything that
- // used F (a declaration) with the new Function* (which will be
- // a definition).
- //
- // This happens if there is a prototype for a function
- // (e.g. "int f()") and then a definition of a different type
- // (e.g. "int f(int x)"). Start by making a new function of the
- // correct type, RAUW, then steal the name.
- llvm::GlobalValue *NewFn = EmitForwardFunctionDefinition(D, Ty, true);
- NewFn->takeName(Entry);
-
- // Replace uses of F with the Function we will endow with a body.
- llvm::Constant *NewPtrForOldDecl =
- llvm::ConstantExpr::getBitCast(NewFn, Entry->getType());
- Entry->replaceAllUsesWith(NewPtrForOldDecl);
-
- // Ok, delete the old function now, which is dead.
- assert(Entry->isDeclaration() && "Shouldn't replace non-declaration");
- Entry->eraseFromParent();
-
- Entry = NewFn;
+ } else {
+ // If the types mismatch then we have to rewrite the definition.
+ if (Entry->getType() != llvm::PointerType::getUnqual(Ty)) {
+ // Otherwise, we have a definition after a prototype with the
+ // wrong type. F is the Function* for the one with the wrong
+ // type, we must make a new Function* and update everything that
+ // used F (a declaration) with the new Function* (which will be
+ // a definition).
+ //
+ // This happens if there is a prototype for a function
+ // (e.g. "int f()") and then a definition of a different type
+ // (e.g. "int f(int x)"). Start by making a new function of the
+ // correct type, RAUW, then steal the name.
+ llvm::GlobalValue *NewFn = EmitForwardFunctionDefinition(D, Ty);
+ NewFn->takeName(Entry);
+
+ // Replace uses of F with the Function we will endow with a body.
+ llvm::Constant *NewPtrForOldDecl =
+ llvm::ConstantExpr::getBitCast(NewFn, Entry->getType());
+ Entry->replaceAllUsesWith(NewPtrForOldDecl);
+
+ // Ok, delete the old function now, which is dead.
+ assert(Entry->isDeclaration() && "Shouldn't replace non-declaration");
+ Entry->eraseFromParent();
+
+ Entry = NewFn;
+ }
}
llvm::Function *Fn = cast<llvm::Function>(Entry);
OpenPOWER on IntegriCloud