From: Pete Cooper Date: Tue, 18 Dec 2018 22:42:08 +0000 (+0000) Subject: Preserve the linkage for objc* intrinsics as clang will set them to weak_external... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a95f98a319e6a134b842beb3a699918f2f0184a;p=llvm Preserve the linkage for objc* intrinsics as clang will set them to weak_external in some cases Clang uses weak linkage for objc runtime functions when they are not available on the platform. The intrinsic has this linkage so we just need to pass that on to the runtime call. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349559 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/PreISelIntrinsicLowering.cpp b/lib/CodeGen/PreISelIntrinsicLowering.cpp index 3689dab2331..b0e9ac03612 100644 --- a/lib/CodeGen/PreISelIntrinsicLowering.cpp +++ b/lib/CodeGen/PreISelIntrinsicLowering.cpp @@ -66,12 +66,15 @@ static bool lowerObjCCall(Function &F, const char *NewFn, // program already contains a function with this name. Module *M = F.getParent(); Constant* FCache = M->getOrInsertFunction(NewFn, F.getFunctionType()); - - // If we have Native ARC, set nonlazybind attribute for these APIs for - // performance. - if (setNonLazyBind) - if (Function* Fn = dyn_cast(FCache)) + + if (Function* Fn = dyn_cast(FCache)) { + Fn->setLinkage(F.getLinkage()); + if (setNonLazyBind && !Fn->isWeakForLinker()) { + // If we have Native ARC, set nonlazybind attribute for these APIs for + // performance. Fn->addFnAttr(Attribute::NonLazyBind); + } + } for (auto I = F.use_begin(), E = F.use_end(); I != E;) { auto *CI = dyn_cast(I->getUser()); diff --git a/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll b/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll index 235ef65beee..8b7d11ea75f 100644 --- a/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll +++ b/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll @@ -260,7 +260,7 @@ declare i8* @llvm.objc.autoreleasePoolPush() declare i8* @llvm.objc.autoreleaseReturnValue(i8*) declare void @llvm.objc.copyWeak(i8**, i8**) declare void @llvm.objc.destroyWeak(i8**) -declare i8* @llvm.objc.initWeak(i8**, i8*) +declare extern_weak i8* @llvm.objc.initWeak(i8**, i8*) declare i8* @llvm.objc.loadWeak(i8**) declare i8* @llvm.objc.loadWeakRetained(i8**) declare void @llvm.objc.moveWeak(i8**, i8**) @@ -280,7 +280,33 @@ declare i8* @llvm.objc.retain.autorelease(i8*) declare i32 @llvm.objc.sync.enter(i8*) declare i32 @llvm.objc.sync.exit(i8*) +attributes #0 = { nounwind } + +; CHECK: declare i8* @objc_autorelease(i8*) +; CHECK: declare void @objc_autoreleasePoolPop(i8*) +; CHECK: declare i8* @objc_autoreleasePoolPush() +; CHECK: declare i8* @objc_autoreleaseReturnValue(i8*) +; CHECK: declare void @objc_copyWeak(i8**, i8**) +; CHECK: declare void @objc_destroyWeak(i8**) +; CHECK: declare extern_weak i8* @objc_initWeak(i8**, i8*) +; CHECK: declare i8* @objc_loadWeak(i8**) +; CHECK: declare i8* @objc_loadWeakRetained(i8**) +; CHECK: declare void @objc_moveWeak(i8**, i8**) ; CHECK: declare void @objc_release(i8*) [[NLB:#[0-9]+]] ; CHECK: declare i8* @objc_retain(i8*) [[NLB]] +; CHECK: declare i8* @objc_retainAutorelease(i8*) +; CHECK: declare i8* @objc_retainAutoreleaseReturnValue(i8*) +; CHECK: declare i8* @objc_retainAutoreleasedReturnValue(i8*) +; CHECK: declare i8* @objc_retainBlock(i8*) +; CHECK: declare void @objc_storeStrong(i8**, i8*) +; CHECK: declare i8* @objc_storeWeak(i8**, i8*) +; CHECK: declare i8* @objc_unsafeClaimAutoreleasedReturnValue(i8*) +; CHECK: declare i8* @objc_retainedObject(i8*) +; CHECK: declare i8* @objc_unretainedObject(i8*) +; CHECK: declare i8* @objc_unretainedPointer(i8*) +; CHECK: declare i8* @objc_retain_autorelease(i8*) +; CHECK: declare i32 @objc_sync_enter(i8*) +; CHECK: declare i32 @objc_sync_exit(i8*) +; CHECK: attributes #0 = { nounwind } ; CHECK: attributes [[NLB]] = { nonlazybind }