From 554b07d30484185a313dbe2c5e2fd5798ac3f998 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Sat, 2 Feb 2013 00:57:44 +0000 Subject: [PATCH] On platforms which do not support ARC natively, do not mark objc_retain/objc_release as "nonlazybind". rdar://13108298. rdar://13129783. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174253 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjC.cpp | 10 ++++++---- test/CodeGenObjC/arc.m | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index e861222cf5..d667e1aacb 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -1705,16 +1705,18 @@ static llvm::Constant *createARCRuntimeFunction(CodeGenModule &CGM, StringRef fnName) { llvm::Constant *fn = CGM.CreateRuntimeFunction(type, fnName); + if (llvm::Function *f = dyn_cast(fn)) { // If the target runtime doesn't naturally support ARC, emit weak // references to the runtime support library. We don't really // permit this to fail, but we need a particular relocation style. - if (llvm::Function *f = dyn_cast(fn)) { - if (!CGM.getLangOpts().ObjCRuntime.hasNativeARC()) + if (!CGM.getLangOpts().ObjCRuntime.hasNativeARC()) { f->setLinkage(llvm::Function::ExternalWeakLinkage); - // set nonlazybind attribute for these APIs for performance. - if (fnName == "objc_retain" || fnName == "objc_release") + } else if (fnName == "objc_retain" || fnName == "objc_release") { + // If we have Native ARC, set nonlazybind attribute for these APIs for + // performance. f->addFnAttr(llvm::Attribute::NonLazyBind); } + } return fn; } diff --git a/test/CodeGenObjC/arc.m b/test/CodeGenObjC/arc.m index bac966165a..ca100e4762 100644 --- a/test/CodeGenObjC/arc.m +++ b/test/CodeGenObjC/arc.m @@ -1,6 +1,37 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-optzns -o - %s | FileCheck %s // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-GLOBALS %s +// rdar://13129783. Check both native/non-native arc platforms. Here we check +// that they treat nonlazybind differently. +// RUN: %clang_cc1 -fobjc-runtime=macosx-10.6.0 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-ALIEN %s +// RUN: %clang_cc1 -fobjc-runtime=macosx-10.7.0 -triple x86_64-apple-darwin11 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-NATIVE %s + +// ARC-ALIEN: declare extern_weak i8* @objc_retain(i8*) +// ARC-ALIEN: declare extern_weak void @objc_storeStrong(i8**, i8*) +// ARC-ALIEN: declare extern_weak i8* @objc_autoreleaseReturnValue(i8*) +// ARC-ALIEN: declare i8* @objc_msgSend(i8*, i8*, ...) nonlazybind +// ARC-ALIEN: declare extern_weak void @objc_release(i8*) +// ARC-ALIEN: declare extern_weak i8* @objc_retainAutoreleasedReturnValue(i8*) +// ARC-ALIEN: declare extern_weak i8* @objc_initWeak(i8**, i8*) +// ARC-ALIEN: declare extern_weak i8* @objc_storeWeak(i8**, i8*) +// ARC-ALIEN: declare extern_weak i8* @objc_loadWeakRetained(i8**) +// ARC-ALIEN: declare extern_weak void @objc_destroyWeak(i8**) +// ARC-ALIEN: declare extern_weak i8* @objc_autorelease(i8*) +// ARC-ALIEN: declare extern_weak i8* @objc_retainAutorelease(i8*) + +// ARC-NATIVE: declare i8* @objc_retain(i8*) nonlazybind +// ARC-NATIVE: declare void @objc_storeStrong(i8**, i8*) +// ARC-NATIVE: declare i8* @objc_autoreleaseReturnValue(i8*) +// ARC-NATIVE: declare i8* @objc_msgSend(i8*, i8*, ...) nonlazybind +// ARC-NATIVE: declare void @objc_release(i8*) nonlazybind +// ARC-NATIVE: declare i8* @objc_retainAutoreleasedReturnValue(i8*) +// ARC-NATIVE: declare i8* @objc_initWeak(i8**, i8*) +// ARC-NATIVE: declare i8* @objc_storeWeak(i8**, i8*) +// ARC-NATIVE: declare i8* @objc_loadWeakRetained(i8**) +// ARC-NATIVE: declare void @objc_destroyWeak(i8**) +// ARC-NATIVE: declare i8* @objc_autorelease(i8*) +// ARC-NATIVE: declare i8* @objc_retainAutorelease(i8*) + // CHECK: define void @test0 void test0(id x) { // CHECK: [[X:%.*]] = alloca i8* @@ -9,9 +40,6 @@ void test0(id x) { // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) // CHECK-NEXT: ret void -// rdar://12040837 - // CHECK: declare extern_weak i8* @objc_retain(i8*) nonlazybind - // CHECK: declare extern_weak void @objc_release(i8*) nonlazybind } // CHECK: define i8* @test1(i8* -- 2.40.0