Home | History | Annotate | Download | only in CodeGenObjC
      1 // REQUIRES: x86-registered-target
      2 // RUN: %clang_cc1 -emit-llvm -fblocks -fobjc-arc -g -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
      3 
      4 // rdar://11562117
      5 typedef unsigned int NSUInteger;
      6 typedef long NSInteger;
      7 typedef signed char BOOL;
      8 
      9 #define nil ((void*) 0)
     10 #define YES             ((BOOL)1)
     11 #define NO              ((BOOL)0)
     12 
     13 @interface NSObject
     14 - (id)init;
     15 @end
     16 
     17 @interface NSError : NSObject
     18 @end
     19 
     20 @interface NSString : NSObject
     21 @end
     22 
     23 @interface NSString (NSStringExtensionMethods)
     24 - (void)enumerateLinesUsingBlock:(void (^)(NSString *line, BOOL *stop))block;
     25 @end
     26 
     27 @interface NSData : NSObject
     28 @end
     29 
     30 @interface NSData (ASBase64)
     31 - (NSString *)encodedString:(NSInteger)position;
     32 - (NSData *)compressedData;
     33 @end
     34 
     35 typedef void (^TDataCompletionBlock)(NSData *data, NSError *error);
     36 @interface TMap : NSObject
     37 - (NSString *)identifier;
     38 - (NSString *)name;
     39 + (TMap *)mapForID:(NSString *)identifier;
     40 - (void)dataWithCompletionBlock:(TDataCompletionBlock)block;
     41 @end
     42 
     43 typedef enum : NSUInteger {
     44     TOK                = 100,
     45     TError = 125,
     46 } TResponseCode;
     47 
     48 @interface TConnection : NSObject
     49 - (void)sendString:(NSString *)string;
     50 - (void)sendFormat:(NSString *)format, ...;
     51 - (void)sendResponseCode:(TResponseCode)responseCode dataFollows:(BOOL)flag
     52                          format:(NSString *)format, ...;
     53 @end
     54 
     55 @interface TServer : NSObject
     56 @end
     57 
     58 @implementation TServer
     59 - (void)serverConnection:(TConnection *)connection getCommand:(NSString *)str
     60 {
     61     NSString    *mapID = nil;
     62     TMap       *map = [TMap mapForID:mapID];
     63 // Make sure we do not map code generated for the block to the above line.
     64 // CHECK: define internal void @"__39-[TServer serverConnection:getCommand:]_block_invoke"
     65 // CHECK: call void @objc_storeStrong(i8** [[ZERO:%.*]], i8* [[ONE:%.*]]) [[NUW:#[0-9]+]]
     66 // CHECK: call void @objc_storeStrong(i8** [[TWO:%.*]], i8* [[THREE:%.*]]) [[NUW]]
     67 // CHECK: call {{.*}}@objc_msgSend{{.*}}, !dbg ![[LINE_ABOVE:[0-9]+]]
     68 // CHECK: getelementptr
     69 // CHECK-NOT: !dbg, ![[LINE_ABOVE]]
     70 // CHECK: bitcast %5** [[TMP:%.*]] to i8**
     71 // CHECK-NOT: !dbg, ![[LINE_ABOVE]]
     72 // CHECK: call void @objc_storeStrong(i8** [[VAL1:%.*]], i8* null) [[NUW]]
     73 // CHECK-NEXT: bitcast %4** [[TMP:%.*]] to i8**
     74 // CHECK-NEXT: call void @objc_storeStrong(i8** [[VAL2:%.*]], i8* null) [[NUW]]
     75 // CHECK-NEXT: ret
     76 // CHECK: attributes [[NUW]] = { nounwind }
     77     [map dataWithCompletionBlock:^(NSData *data, NSError *error) {
     78         if (data) {
     79             NSString    *encoded = [[data compressedData] encodedString:18];
     80             [connection sendResponseCode:TOK dataFollows:YES
     81                 format:@"Sending \"%@\" (%@)", [map name], [map identifier]];
     82             [encoded enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) {
     83                 [connection sendFormat:@"%@\r\n", line];
     84             }];
     85             [connection sendString:@".\r\n"];
     86         } else {
     87             [connection sendResponseCode:TError dataFollows:NO
     88                 format:@"Failed \"%@\" (%@)", [map name], [map identifier]];
     89         }
     90     }];
     91 }
     92 @end
     93