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 = (__bridge NSString *)kUTTypePlainText;
32  str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText);
33  str = (__bridge NSString *)(b ? kUTTypeRTF : kUTTypePlainText);
34  str = (NSString *)p; // no change.
35
36  CFUUIDRef   _uuid;
37  NSString *_uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, _uuid));
38  _uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, _uuid));
39  _uuidString = CFBridgingRelease(CFRetain(_uuid));
40}
41
42@implementation NSString (StrExt)
43- (NSString *)stringEscapedAsURI {
44  CFStringRef str = (__bridge CFStringRef)self;
45  CFStringRef str2 = (__bridge CFStringRef)(self);
46  return self;
47}
48@end
49
50@implementation NSString
51-(id)string {
52  if (0)
53    return (__bridge id)(sref);
54  else
55    return (__bridge id)(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 = (__bridge CFStringRef)([s string]);
64  ref = (__bridge CFStringRef)[s string];
65  ref = (__bridge CFStringRef)(s.string);
66  ref = CFBridgingRetain([NSString new]);
67  ref = CFBridgingRetain([s newString]);
68  ref = (CFStringRef)CFBridgingRetain([NSString new]);
69  ref = CFBridgingRetain([[NSString alloc] init]);
70  ref = CFBridgingRetain([s string]);
71  ref = (CFStringRef)CFBridgingRetain([s string]);
72  ref = CFBridgingRetain([s string]);
73  ref = CFBridgingRetain(s);
74  ref = CFBridgingRetain(s);
75
76  consumeParam((CFStringRef)CFBridgingRetain(s));
77  consumeParam(CFBridgingRetain(s));
78}
79