1// 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
3// RUN: diff %t %s.result
4
5#include "Common.h"
6
7typedef 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
18struct 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
30void 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
36  CFUUIDRef   _uuid;
37  NSString *_uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid);
38  _uuidString = [(NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid) autorelease];
39  _uuidString = CFRetain(_uuid);
40}
41
42@implementation NSString (StrExt)
43- (NSString *)stringEscapedAsURI {
44  CFStringRef str = (CFStringRef)self;
45  CFStringRef str2 = self;
46  return self;
47}
48@end
49
50@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
60extern void consumeParam(CFStringRef CF_CONSUMED p);
61
62void 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];
75
76  consumeParam((CFStringRef)s);
77  consumeParam(s);
78}
79