diff options
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 13 | ||||
-rw-r--r-- | test/CodeGen/attr-weakref.c | 6 |
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 6be225c6b5..3353612c90 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -884,6 +884,10 @@ llvm::Constant *CodeGenModule::GetWeakRefReference(const ValueDecl *VD) { // See if there is already something with the target's name in the module. llvm::GlobalValue *Entry = GetGlobalValue(AA->getAliasee()); + if (Entry) { + unsigned AS = getContext().getTargetAddressSpace(VD->getType()); + return llvm::ConstantExpr::getBitCast(Entry, DeclTy->getPointerTo(AS)); + } llvm::Constant *Aliasee; if (isa<llvm::FunctionType>(DeclTy)) @@ -893,11 +897,10 @@ llvm::Constant *CodeGenModule::GetWeakRefReference(const ValueDecl *VD) { else Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), llvm::PointerType::getUnqual(DeclTy), 0); - if (!Entry) { - llvm::GlobalValue* F = cast<llvm::GlobalValue>(Aliasee); - F->setLinkage(llvm::Function::ExternalWeakLinkage); - WeakRefReferences.insert(F); - } + + llvm::GlobalValue* F = cast<llvm::GlobalValue>(Aliasee); + F->setLinkage(llvm::Function::ExternalWeakLinkage); + WeakRefReferences.insert(F); return Aliasee; } diff --git a/test/CodeGen/attr-weakref.c b/test/CodeGen/attr-weakref.c index c1cc03b668..560d39141c 100644 --- a/test/CodeGen/attr-weakref.c +++ b/test/CodeGen/attr-weakref.c @@ -53,6 +53,12 @@ void test6_foo(void) { test6_f(); } +// CHECK: declare extern_weak void @test8_f() +static void test8_g(void) __attribute__((weakref("test8_f"))); +void test8_h(void) { + if (test8_g) + test8_g(); +} // CHECK: declare extern_weak void @test7_f() void test7_f(void); static void test7_g(void) __attribute__((weakref("test7_f"))); |