Description
Previous ID | SR-2755 |
Radar | None |
Original Reporter | gmilos (JIRA User) |
Type | Bug |
Attachment: Download
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug |
Assignee | @slavapestov |
Priority | Medium |
md5: 89cbd7095952971a44b28957ee5b5db8
relates to:
- SR-5271 Don't emit objc_retainAutoreleasedReturnValue() on non-ObjC targets
Issue Description:
When building Swift code, which calls to a C API taking block with block return value, generates false objc_autoreleaseReturnValue
dependency.
From the attached minimal reproduction:
sbs:/tmp/objc_autoreleaseReturnValue_bug$
cat CStuff/c-stuff.c
#include "c-stuff.h"#ifdef DEFINE_AUTORELEASE_RETURN_VALUE
void *objc_autoreleaseReturnValue(void * a) {
return a;
}
#endifvoid bar(SomeBlock b) {
b();
}
sbs:/tmp/objc_autoreleaseReturnValue_bug$
cat CStuff/c-stuff.h
#ifndef C_STUFF
#define C_STUFFtypedef void(^SomeOtherBlock)(void);
typedef SomeOtherBlock(^SomeBlock)(void);
void bar(SomeBlock b);#endif
sbs:/tmp/objc_autoreleaseReturnValue_bug$
cat
CStuff/ libCStuff.so Makefile test.o test.swift
sbs:/tmp/objc_autoreleaseReturnValue_bug$
cat test.swift
import Dispatch
import CStuffbar({ return {} })
sbs:/tmp/objc_autoreleaseReturnValue_bug$
make
swiftc -lswiftCore -lswiftSwiftOnoneSupport -o test test.o libCStuff.so
test.o:test.o:function TTRXFooGSqFT_TXFdCbaGSqbT_T**_: error: undefined reference to 'objc_autoreleaseReturnValue'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 1
The objc_autoreleaseReturnValue
dependency doesn't exist on Linux. I was able to verify that the code builds and works when defining the symbol myself (simple identity function). This can be tested building with make clean && make CFLAGS=-DDEFINE_AUTORELEASE_RETURN_VALUE
Explicit Block_retain/Block_release
should be used to manage return value lifecycle instead.