aboutsummaryrefslogtreecommitdiff
path: root/test/ARCMT
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-06-07 00:44:06 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-06-07 00:44:06 +0000
commit76a5245d7fb558625453ebe2281ee0bc9c93c245 (patch)
treef1d84c4ae755e8b86c4b9008be6700542340ae61 /test/ARCMT
parente14da79c7b1c336b72e6a4548f53b1a9534f7e0d (diff)
[arcmt] At an unbridged cast error, if we're returning a load-of-ivar from a +0 method,
automatically insert a __bridge cast. radar://11560638 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158127 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/ARCMT')
-rw-r--r--test/ARCMT/nonobjc-to-objc-cast-2.m31
-rw-r--r--test/ARCMT/nonobjc-to-objc-cast.m27
-rw-r--r--test/ARCMT/nonobjc-to-objc-cast.m.result27
3 files changed, 70 insertions, 15 deletions
diff --git a/test/ARCMT/nonobjc-to-objc-cast-2.m b/test/ARCMT/nonobjc-to-objc-cast-2.m
index 1ec0089f08..80d694e586 100644
--- a/test/ARCMT/nonobjc-to-objc-cast-2.m
+++ b/test/ARCMT/nonobjc-to-objc-cast-2.m
@@ -3,16 +3,37 @@
#include "Common.h"
-@interface NSString : NSObject
--(id)string;
--(id)newString;
-@end
-
typedef const struct __CFString * CFStringRef;
typedef const void * CFTypeRef;
CFTypeRef CFBridgingRetain(id X);
id CFBridgingRelease(CFTypeRef);
+struct StrS {
+ CFStringRef sref_member;
+};
+
+@interface NSString : NSObject {
+ CFStringRef sref;
+ struct StrS *strS;
+}
+-(id)string;
+-(id)newString;
+@end
+
+@implementation NSString
+-(id)string {
+ if (0)
+ return sref;
+ else
+ return strS->sref_member;
+}
+-(id)newString {
+ return sref; // expected-error {{implicit conversion of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'id' requires a bridged cast}} \
+ // expected-note{{use __bridge to convert directly (no change in ownership)}} \
+ // expected-note{{use CFBridgingRelease call to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}}
+}
+@end
+
void f(BOOL b) {
CFStringRef cfstr;
NSString *str = (NSString *)cfstr; // expected-error {{cast of C pointer type 'CFStringRef' (aka 'const struct __CFString *') to Objective-C pointer type 'NSString *' requires a bridged cast}} \
diff --git a/test/ARCMT/nonobjc-to-objc-cast.m b/test/ARCMT/nonobjc-to-objc-cast.m
index fcdcd89c9c..55b6655fa4 100644
--- a/test/ARCMT/nonobjc-to-objc-cast.m
+++ b/test/ARCMT/nonobjc-to-objc-cast.m
@@ -5,11 +5,6 @@
#include "Common.h"
-@interface NSString : NSObject
--(id)string;
--(id)newString;
-@end
-
typedef const struct __CFString * CFStringRef;
extern const CFStringRef kUTTypePlainText;
extern const CFStringRef kUTTypeRTF;
@@ -21,6 +16,18 @@ extern const CFAllocatorRef kCFAllocatorDefault;
extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
+struct StrS {
+ CFStringRef sref_member;
+};
+
+@interface NSString : NSObject {
+ CFStringRef sref;
+ struct StrS *strS;
+}
+-(id)string;
+-(id)newString;
+@end
+
void f(BOOL b, id p) {
NSString *str = (NSString *)kUTTypePlainText;
str = b ? kUTTypeRTF : kUTTypePlainText;
@@ -41,6 +48,16 @@ void f(BOOL b, id p) {
}
@end
+@implementation NSString
+-(id)string {
+ if (0)
+ return sref;
+ else
+ return strS->sref_member;
+}
+-(id)newString { return 0; }
+@end
+
extern void consumeParam(CFStringRef CF_CONSUMED p);
void f2(NSString *s) {
diff --git a/test/ARCMT/nonobjc-to-objc-cast.m.result b/test/ARCMT/nonobjc-to-objc-cast.m.result
index 0a3b2bb526..4f508f6adf 100644
--- a/test/ARCMT/nonobjc-to-objc-cast.m.result
+++ b/test/ARCMT/nonobjc-to-objc-cast.m.result
@@ -5,11 +5,6 @@
#include "Common.h"
-@interface NSString : NSObject
--(id)string;
--(id)newString;
-@end
-
typedef const struct __CFString * CFStringRef;
extern const CFStringRef kUTTypePlainText;
extern const CFStringRef kUTTypeRTF;
@@ -21,6 +16,18 @@ extern const CFAllocatorRef kCFAllocatorDefault;
extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
+struct StrS {
+ CFStringRef sref_member;
+};
+
+@interface NSString : NSObject {
+ CFStringRef sref;
+ struct StrS *strS;
+}
+-(id)string;
+-(id)newString;
+@end
+
void f(BOOL b, id p) {
NSString *str = (__bridge NSString *)kUTTypePlainText;
str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText);
@@ -41,6 +48,16 @@ void f(BOOL b, id p) {
}
@end
+@implementation NSString
+-(id)string {
+ if (0)
+ return (__bridge id)(sref);
+ else
+ return (__bridge id)(strS->sref_member);
+}
+-(id)newString { return 0; }
+@end
+
extern void consumeParam(CFStringRef CF_CONSUMED p);
void f2(NSString *s) {