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;
10extern CFStringRef kNonConst;
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
19struct 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
31void f(BOOL b, id p) {
32  NSString *str = (NSString *)kUTTypePlainText; // no change
33  str = b ? kUTTypeRTF : kUTTypePlainText; // no change
34  str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText); // no change
35  str = (NSString *)p; // no change.
36
37  str = (__bridge NSString *)kNonConst;
38  str = (__bridge NSString *)(b ? kUTTypeRTF : kNonConst);
39  str = (__bridge NSString *)(b ? kUTTypeRTF : kNonConst);
40
41  CFUUIDRef   _uuid;
42  NSString *_uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, _uuid));
43  _uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, _uuid));
44  _uuidString = CFBridgingRelease(CFRetain(_uuid));
45}
46
47@implementation NSString (StrExt)
48- (NSString *)stringEscapedAsURI {
49  CFStringRef str = (__bridge CFStringRef)self;
50  CFStringRef str2 = (__bridge CFStringRef)(self);
51  return self;
52}
53@end
54
55@implementation NSString
56-(id)string {
57  if (0)
58    return (__bridge id)(sref);
59  else
60    return (__bridge id)(strS->sref_member);
61}
62-(id)newString { return 0; }
63@end
64
65extern void consumeParam(CFStringRef CF_CONSUMED p);
66
67void f2(NSString *s) {
68  CFStringRef ref = (__bridge CFStringRef)([s string]);
69  ref = (__bridge CFStringRef)[s string];
70  ref = (__bridge CFStringRef)(s.string);
71  ref = CFBridgingRetain([NSString new]);
72  ref = CFBridgingRetain([s newString]);
73  ref = (CFStringRef)CFBridgingRetain([NSString new]);
74  ref = CFBridgingRetain([[NSString alloc] init]);
75  ref = CFBridgingRetain([s string]);
76  ref = (CFStringRef)CFBridgingRetain([s string]);
77  ref = CFBridgingRetain([s string]);
78  ref = CFBridgingRetain(s);
79  ref = CFBridgingRetain(s);
80
81  consumeParam((CFStringRef)CFBridgingRetain(s));
82  consumeParam(CFBridgingRetain(s));
83}
84