2011-11-08 10:02:38 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -x objective-c %s.result
|
|
|
|
// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c %s > %t
|
|
|
|
// RUN: diff %t %s.result
|
|
|
|
// RUN: arcmt-test --args -triple x86_64-apple-macosx10.6 -fsyntax-only -fobjc-gc-only -x objective-c++ %s > %t
|
|
|
|
// RUN: diff %t %s.result
|
|
|
|
|
Define weak and __weak to mean ARC-style weak references, even in MRC.
Previously, __weak was silently accepted and ignored in MRC mode.
That makes this a potentially source-breaking change that we have to
roll out cautiously. Accordingly, for the time being, actual support
for __weak references in MRC is experimental, and the compiler will
reject attempts to actually form such references. The intent is to
eventually enable the feature by default in all non-GC modes.
(It is, of course, incompatible with ObjC GC's interpretation of
__weak.)
If you like, you can enable this feature with
-Xclang -fobjc-weak
but like any -Xclang option, this option may be removed at any point,
e.g. if/when it is eventually enabled by default.
This patch also enables the use of the ARC __unsafe_unretained qualifier
in MRC. Unlike __weak, this is being enabled immediately. Since
variables are essentially __unsafe_unretained by default in MRC,
the only practical uses are (1) communication and (2) changing the
default behavior of by-value block capture.
As an implementation matter, this means that the ObjC ownership
qualifiers may appear in any ObjC language mode, and so this patch
removes a number of checks for getLangOpts().ObjCAutoRefCount
that were guarding the processing of these qualifiers. I don't
expect this to be a significant drain on performance; it may even
be faster to just check for these qualifiers directly on a type
(since it's probably in a register anyway) than to do N dependent
loads to grab the LangOptions.
rdar://9674298
llvm-svn: 251041
2015-10-23 02:38:17 +08:00
|
|
|
// MRC __weak broke this test somehow.
|
|
|
|
// XFAIL: *
|
|
|
|
|
2011-11-08 10:02:38 +08:00
|
|
|
#include "Common.h"
|
|
|
|
#include "GC.h"
|
|
|
|
|
|
|
|
void test1(CFTypeRef *cft) {
|
|
|
|
id x = NSMakeCollectable(cft);
|
|
|
|
}
|
|
|
|
|
2012-02-25 09:57:42 +08:00
|
|
|
@interface I1
|
2011-11-08 10:02:38 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation I1
|
|
|
|
-(void)dealloc {
|
|
|
|
// dealloc
|
|
|
|
test1(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)finalize {
|
|
|
|
// finalize
|
|
|
|
test1(0);
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface I2
|
|
|
|
@property (retain) id prop;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation I2
|
|
|
|
@synthesize prop;
|
|
|
|
|
|
|
|
-(void)finalize {
|
|
|
|
self.prop = 0;
|
|
|
|
// finalize
|
|
|
|
test1(0);
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
__attribute__((objc_arc_weak_reference_unavailable))
|
|
|
|
@interface QQ {
|
|
|
|
__weak id s;
|
|
|
|
__weak QQ *q;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface I3
|
|
|
|
@property (assign) I3 *__weak pw1, *__weak pw2;
|
|
|
|
@property (assign) I3 *__strong ps;
|
|
|
|
@property (assign) I3 * pds;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface I4Impl {
|
|
|
|
I4Impl *pds2;
|
|
|
|
}
|
|
|
|
@property (assign) I4Impl *__weak pw1, *__weak pw2;
|
|
|
|
@property (assign) I4Impl *__strong ps;
|
|
|
|
@property (assign) I4Impl * pds;
|
|
|
|
@property (assign) I4Impl * pds2;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation I4Impl
|
|
|
|
@synthesize pw1, pw2, ps, pds, pds2;
|
|
|
|
|
|
|
|
-(void)test1:(CFTypeRef *)cft {
|
|
|
|
id x = NSMakeCollectable(cft);
|
|
|
|
}
|
|
|
|
@end
|
2011-11-28 10:04:36 +08:00
|
|
|
|
|
|
|
@interface I5 {
|
|
|
|
__weak id prop;
|
|
|
|
}
|
|
|
|
@property (readonly) __weak id prop;
|
|
|
|
@end
|