diff options
author | Mike Stump <mrs@apple.com> | 2009-02-27 22:42:30 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-02-27 22:42:30 +0000 |
commit | 537abb0dec331bc51f5c0db139bf82963b17e903 (patch) | |
tree | 1e7f8a5310d3872c3832a54cfe8f6d18d5424da1 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | f5c1c923e8fd963d048c0bb14d43c25e4bf87e23 (diff) | |
download | bcm5719-llvm-537abb0dec331bc51f5c0db139bf82963b17e903.tar.gz bcm5719-llvm-537abb0dec331bc51f5c0db139bf82963b17e903.zip |
Fix PR3612. We ensure that we add builtins to the GlobalDeclMap and
we ensure that things added to the module can be found even when they
are not in GlobalDeclMap. The later is for increased flexibility,
should someone want to do something tricky like extern "Ada" in the
same module.
llvm-svn: 65657
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6ebe12706bd..a812ba9352b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -794,6 +794,8 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(const FunctionDecl *D) { // Lookup the entry, lazily creating it if necessary. llvm::GlobalValue *&Entry = GlobalDeclMap[getMangledName(D)]; if (!Entry) + Entry = getModule().getFunction(getMangledName(D)); + if (!Entry) Entry = EmitForwardFunctionDefinition(D, 0); return llvm::ConstantExpr::getBitCast(Entry, PTy); @@ -872,14 +874,14 @@ void CodeGenModule::UpdateCompletedType(const TagDecl *TD) { /// getBuiltinLibFunction -llvm::Function *CodeGenModule::getBuiltinLibFunction(unsigned BuiltinID) { +llvm::Value *CodeGenModule::getBuiltinLibFunction(unsigned BuiltinID) { if (BuiltinID > BuiltinFunctions.size()) BuiltinFunctions.resize(BuiltinID); // Cache looked up functions. Since builtin id #0 is invalid we don't reserve // a slot for it. assert(BuiltinID && "Invalid Builtin ID"); - llvm::Function *&FunctionSlot = BuiltinFunctions[BuiltinID-1]; + llvm::Value *&FunctionSlot = BuiltinFunctions[BuiltinID-1]; if (FunctionSlot) return FunctionSlot; @@ -913,8 +915,15 @@ llvm::Function *CodeGenModule::getBuiltinLibFunction(unsigned BuiltinID) { assert(Existing == 0 && "FIXME: Name collision"); } + llvm::GlobalValue *&ExitingFn = GlobalDeclMap[getContext().Idents.get(Name).getName()]; + if (ExitingFn) { + llvm::Function *Fn = dyn_cast<llvm::Function>(ExitingFn); + assert(Fn && "builting mixing with non-function"); + return FunctionSlot = llvm::ConstantExpr::getBitCast(Fn, Ty); + } + // FIXME: param attributes for sext/zext etc. - return FunctionSlot = + return FunctionSlot = ExitingFn = llvm::Function::Create(Ty, llvm::Function::ExternalLinkage, Name, &getModule()); } |