blob: 4f508f6adfb67ed2ae2df77028521481d8f44a4e [file] [log] [blame]
John McCalld1e40d52011-10-02 01:16:38 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -fobjc-arc -x objective-c %s.result
2// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s > %t
John McCall8f0e8d22011-06-15 23:25:17 +00003// RUN: diff %t %s.result
Argyrios Kyrtzidisd8b42162012-01-12 02:34:32 +00004// DISABLE: mingw32
John McCall8f0e8d22011-06-15 23:25:17 +00005
6#include "Common.h"
7
John McCall8f0e8d22011-06-15 23:25:17 +00008typedef const struct __CFString * CFStringRef;
9extern const CFStringRef kUTTypePlainText;
10extern const CFStringRef kUTTypeRTF;
11
12typedef const struct __CFAllocator * CFAllocatorRef;
13typedef const struct __CFUUID * CFUUIDRef;
14
15extern const CFAllocatorRef kCFAllocatorDefault;
16
17extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
18
Argyrios Kyrtzidis76a52452012-06-07 00:44:06 +000019struct StrS {
20 CFStringRef sref_member;
21};
22
23@interface NSString : NSObject {
24 CFStringRef sref;
25 struct StrS *strS;
26}
27-(id)string;
28-(id)newString;
29@end
30
John McCall8f0e8d22011-06-15 23:25:17 +000031void f(BOOL b, id p) {
32 NSString *str = (__bridge NSString *)kUTTypePlainText;
33 str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText);
34 str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText);
35 str = (NSString *)p; // no change.
36
John McCall8f0e8d22011-06-15 23:25:17 +000037 CFUUIDRef _uuid;
Argyrios Kyrtzidis684190b2012-06-01 00:10:47 +000038 NSString *_uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, _uuid));
39 _uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, _uuid));
40 _uuidString = CFBridgingRelease(CFRetain(_uuid));
John McCall8f0e8d22011-06-15 23:25:17 +000041}
Argyrios Kyrtzidis8e2ce7f2011-06-20 23:39:20 +000042
43@implementation NSString (StrExt)
44- (NSString *)stringEscapedAsURI {
45 CFStringRef str = (__bridge CFStringRef)self;
46 CFStringRef str2 = (__bridge CFStringRef)(self);
47 return self;
48}
49@end
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +000050
Argyrios Kyrtzidis76a52452012-06-07 00:44:06 +000051@implementation NSString
52-(id)string {
53 if (0)
54 return (__bridge id)(sref);
55 else
56 return (__bridge id)(strS->sref_member);
57}
58-(id)newString { return 0; }
59@end
60
Argyrios Kyrtzidis4532b552011-09-14 18:17:09 +000061extern void consumeParam(CFStringRef CF_CONSUMED p);
62
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +000063void f2(NSString *s) {
64 CFStringRef ref = (__bridge CFStringRef)([s string]);
65 ref = (__bridge CFStringRef)[s string];
66 ref = (__bridge CFStringRef)(s.string);
Argyrios Kyrtzidis684190b2012-06-01 00:10:47 +000067 ref = CFBridgingRetain([NSString new]);
68 ref = CFBridgingRetain([s newString]);
69 ref = (CFStringRef)CFBridgingRetain([NSString new]);
70 ref = CFBridgingRetain([[NSString alloc] init]);
71 ref = CFBridgingRetain([s string]);
72 ref = (CFStringRef)CFBridgingRetain([s string]);
73 ref = CFBridgingRetain([s string]);
74 ref = CFBridgingRetain(s);
75 ref = CFBridgingRetain(s);
Argyrios Kyrtzidis4532b552011-09-14 18:17:09 +000076
Argyrios Kyrtzidis684190b2012-06-01 00:10:47 +000077 consumeParam((CFStringRef)CFBridgingRetain(s));
78 consumeParam(CFBridgingRetain(s));
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +000079}