Skip to content

Commit bb84f17

Browse files
committed
Don't use clang.arc.attachedcall on non-darwin OSs
We have implemented a work-around where we have implemented objc_retainAutoreleasedReturnValue in a library. When using clang.arc.attachedcall llvm might optimize the call to objc_retain which we have not defined a stub for. (Alternatively, we could define objc_retain in swift-corelibs-libdispatch/src/swift/DispatchStubs.cc)
1 parent 2568e45 commit bb84f17

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/IRGen/GenObjC.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,17 @@ llvm::Value *irgen::emitObjCRetainAutoreleasedReturnValue(IRGenFunction &IGF,
161161

162162
// FIXME: Do this on all targets and at -O0 too. This can be enabled only if
163163
// the target backend knows how to handle the operand bundle.
164-
if (IGM.getOptions().shouldOptimize() && (arch == llvm::Triple::aarch64 ||
165-
arch == llvm::Triple::x86_64)) {
164+
// Don't use clang.arc.attachedcall on non-darwin platforms for now. On these
165+
// platforms we have a workaround in-place to deal with the un-availability of
166+
// a arc runtime -- we have implemented objc_retainAutoreleasedReturnValue in
167+
// a library (src/swift/DispatchStubs.cc) as swift_retain.
168+
// Using clang.arc.attachedcall enables a LLVM optimization that can transform
169+
// objc_retainAutoreleasedReturnValue into objc_retain in some circumstances.
170+
// There is no objc_retain stub defined and we would run into missing symbol
171+
// errors.
172+
if (IGM.getOptions().shouldOptimize() && triple.isOSDarwin() &&
173+
(arch == llvm::Triple::aarch64 ||
174+
arch == llvm::Triple::x86_64)) {
166175
auto EP = llvm::Intrinsic::getDeclaration(&IGM.Module,
167176
(llvm::Intrinsic::ID)llvm::Intrinsic::objc_retainAutoreleasedReturnValue);
168177
llvm::Value *bundleArgs[] = {EP};

0 commit comments

Comments
 (0)