Home | History | Annotate | Download | only in ARCMT
      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 
      7 typedef const struct __CFString * CFStringRef;
      8 extern const CFStringRef kUTTypePlainText;
      9 extern const CFStringRef kUTTypeRTF;
     10 extern CFStringRef kNonConst;
     11 
     12 typedef const struct __CFAllocator * CFAllocatorRef;
     13 typedef const struct __CFUUID * CFUUIDRef;
     14 
     15 extern const CFAllocatorRef kCFAllocatorDefault;
     16 
     17 extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
     18 
     19 struct 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 
     31 void 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 = (NSString *)kNonConst;
     38   str = b ? kUTTypeRTF : kNonConst;
     39   str = (NSString *)(b ? kUTTypeRTF : kNonConst);
     40 
     41   CFUUIDRef   _uuid;
     42   NSString *_uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid);
     43   _uuidString = [(NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid) autorelease];
     44   _uuidString = CFRetain(_uuid);
     45 }
     46 
     47 @implementation NSString (StrExt)
     48 - (NSString *)stringEscapedAsURI {
     49   CFStringRef str = (CFStringRef)self;
     50   CFStringRef str2 = self;
     51   return self;
     52 }
     53 @end
     54 
     55 @implementation NSString
     56 -(id)string {
     57   if (0)
     58     return sref;
     59   else
     60     return strS->sref_member;
     61 }
     62 -(id)newString { return 0; }
     63 @end
     64 
     65 extern void consumeParam(CFStringRef CF_CONSUMED p);
     66 
     67 void f2(NSString *s) {
     68   CFStringRef ref = [s string];
     69   ref = (CFStringRef)[s string];
     70   ref = s.string;
     71   ref = [NSString new];
     72   ref = [s newString];
     73   ref = (CFStringRef)[NSString new];
     74   ref = [[NSString alloc] init];
     75   ref = [[s string] retain];
     76   ref = CFRetain((CFStringRef)[s string]);
     77   ref = CFRetain([s string]);
     78   ref = CFRetain(s);
     79   ref = [s retain];
     80 
     81   consumeParam((CFStringRef)s);
     82   consumeParam(s);
     83 }
     84