blob: b7d2a734b9c4f5c5a5b85b818bde5cd8f0d5b33b [file] [log] [blame]
John McCall9b0a7ce2011-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 McCalld70fb982011-06-15 23:25:17 +00003// RUN: diff %t %s.result
4
5#include "Common.h"
6
John McCalld70fb982011-06-15 23:25:17 +00007typedef const struct __CFString * CFStringRef;
8extern const CFStringRef kUTTypePlainText;
9extern const CFStringRef kUTTypeRTF;
10
11typedef const struct __CFAllocator * CFAllocatorRef;
12typedef const struct __CFUUID * CFUUIDRef;
13
14extern const CFAllocatorRef kCFAllocatorDefault;
15
16extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
17
Argyrios Kyrtzidisb03cc792012-06-07 00:44:06 +000018struct StrS {
19 CFStringRef sref_member;
20};
21
22@interface NSString : NSObject {
23 CFStringRef sref;
24 struct StrS *strS;
25}
26-(id)string;
27-(id)newString;
28@end
29
John McCalld70fb982011-06-15 23:25:17 +000030void f(BOOL b, id p) {
31 NSString *str = (NSString *)kUTTypePlainText;
32 str = b ? kUTTypeRTF : kUTTypePlainText;
33 str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText);
34 str = (NSString *)p; // no change.
35
John McCalld70fb982011-06-15 23:25:17 +000036 CFUUIDRef _uuid;
37 NSString *_uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid);
38 _uuidString = [(NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid) autorelease];
Argyrios Kyrtzidis93907472011-07-27 05:28:18 +000039 _uuidString = CFRetain(_uuid);
John McCalld70fb982011-06-15 23:25:17 +000040}
Argyrios Kyrtzidis0a9d6522011-06-20 23:39:20 +000041
42@implementation NSString (StrExt)
43- (NSString *)stringEscapedAsURI {
44 CFStringRef str = (CFStringRef)self;
45 CFStringRef str2 = self;
46 return self;
47}
48@end
Argyrios Kyrtzidis93907472011-07-27 05:28:18 +000049
Argyrios Kyrtzidisb03cc792012-06-07 00:44:06 +000050@implementation NSString
51-(id)string {
52 if (0)
53 return sref;
54 else
55 return strS->sref_member;
56}
57-(id)newString { return 0; }
58@end
59
Argyrios Kyrtzidis41899f32011-09-14 18:17:09 +000060extern void consumeParam(CFStringRef CF_CONSUMED p);
61
Argyrios Kyrtzidis93907472011-07-27 05:28:18 +000062void f2(NSString *s) {
63 CFStringRef ref = [s string];
64 ref = (CFStringRef)[s string];
65 ref = s.string;
66 ref = [NSString new];
67 ref = [s newString];
68 ref = (CFStringRef)[NSString new];
69 ref = [[NSString alloc] init];
70 ref = [[s string] retain];
71 ref = CFRetain((CFStringRef)[s string]);
72 ref = CFRetain([s string]);
73 ref = CFRetain(s);
74 ref = [s retain];
Argyrios Kyrtzidis41899f32011-09-14 18:17:09 +000075
76 consumeParam((CFStringRef)s);
77 consumeParam(s);
Argyrios Kyrtzidis93907472011-07-27 05:28:18 +000078}