llvm-project
83 строки · 2.4 Кб
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 {
20CFStringRef sref_member;
21};
22
23@interface NSString : NSObject {
24CFStringRef sref;
25struct StrS *strS;
26}
27-(id)string;
28-(id)newString;
29@end
30
31void f(BOOL b, id p) {
32NSString *str = (NSString *)kUTTypePlainText; // no change
33str = b ? kUTTypeRTF : kUTTypePlainText; // no change
34str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText); // no change
35str = (NSString *)p; // no change.
36
37str = (__bridge NSString *)kNonConst;
38str = (__bridge NSString *)(b ? kUTTypeRTF : kNonConst);
39str = (__bridge NSString *)(b ? kUTTypeRTF : kNonConst);
40
41CFUUIDRef _uuid;
42NSString *_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 {
49CFStringRef str = (__bridge CFStringRef)self;
50CFStringRef str2 = (__bridge CFStringRef)(self);
51return self;
52}
53@end
54
55@implementation NSString
56-(id)string {
57if (0)
58return (__bridge id)(sref);
59else
60return (__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) {
68CFStringRef ref = (__bridge CFStringRef)([s string]);
69ref = (__bridge CFStringRef)[s string];
70ref = (__bridge CFStringRef)(s.string);
71ref = CFBridgingRetain([NSString new]);
72ref = CFBridgingRetain([s newString]);
73ref = (CFStringRef)CFBridgingRetain([NSString new]);
74ref = CFBridgingRetain([[NSString alloc] init]);
75ref = CFBridgingRetain([s string]);
76ref = (CFStringRef)CFBridgingRetain([s string]);
77ref = CFBridgingRetain([s string]);
78ref = CFBridgingRetain(s);
79ref = CFBridgingRetain(s);
80
81consumeParam((CFStringRef)CFBridgingRetain(s));
82consumeParam(CFBridgingRetain(s));
83}
84