1// Test instrumentation of general constructs in objective C. 2 3// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=clang | FileCheck -check-prefix=PGOGEN %s 4 5// RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata 6// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-use-path=%t.profdata 2>&1 | FileCheck -check-prefix=PGOUSE %s 7 8// PGOUSE-NOT: warning: profile data may be out of date 9 10#ifdef HAVE_FOUNDATION 11 12// Use this to build an instrumented version to regenerate the input file. 13#import <Foundation/Foundation.h> 14 15#else 16 17// Minimal definitions to get this to compile without Foundation.h. 18 19@protocol NSObject 20@end 21 22@interface NSObject <NSObject> 23- (id)init; 24+ (id)alloc; 25@end 26 27struct NSFastEnumerationState; 28@interface NSArray : NSObject 29- (unsigned long) countByEnumeratingWithState: (struct NSFastEnumerationState*) state 30 objects: (id*) buffer 31 count: (unsigned long) bufferSize; 32+(NSArray*) arrayWithObjects: (id) first, ...; 33@end; 34#endif 35 36// PGOGEN: @[[FRC:"__profc_objc_general.m_\+\[A foreach_\]"]] = private global [2 x i64] zeroinitializer 37// PGOGEN: @[[BLC:"__profc_objc_general.m___13\+\[A foreach_\]_block_invoke"]] = private global [2 x i64] zeroinitializer 38// PGOGEN: @[[MAC:__profc_main]] = private global [1 x i64] zeroinitializer 39 40@interface A : NSObject 41+ (void)foreach: (NSArray *)array; 42@end 43 44@implementation A 45// PGOGEN: define {{.*}}+[A foreach:] 46// PGOUSE: define {{.*}}+[A foreach:] 47// PGOGEN: store {{.*}} @[[FRC]] 48+ (void)foreach: (NSArray *)array 49{ 50 __block id result; 51 // PGOGEN: store {{.*}} @[[FRC]], i32 0, i32 1 52 // PGOUSE: br {{.*}} !prof ![[FR1:[0-9]+]] 53 // PGOUSE: br {{.*}} !prof ![[FR2:[0-9]+]] 54 for (id x in array) { 55 // PGOGEN: define {{.*}}_block_invoke 56 // PGOUSE: define {{.*}}_block_invoke 57 // PGOGEN: store {{.*}} @[[BLC]] 58 ^{ 59 static int init = 0; 60 // PGOGEN: store {{.*}} @[[BLC]], i32 0, i32 1 61 // PGOUSE: br {{.*}} !prof ![[BL1:[0-9]+]] 62 if (init) 63 result = x; 64 init = 1; 65 }(); 66 } 67} 68@end 69 70void nested_objc_for_ranges(NSArray *arr) { 71 int x = 0; 72 for (id a in arr) 73 for (id b in arr) 74 ++x; 75} 76 77void consecutive_objc_for_ranges(NSArray *arr) { 78 int x = 0; 79 for (id a in arr) {} 80 for (id b in arr) 81 ++x; 82} 83 84// PGOUSE-DAG: ![[FR1]] = !{!"branch_weights", i32 2, i32 3} 85// PGOUSE-DAG: ![[FR2]] = !{!"branch_weights", i32 3, i32 2} 86// PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i32 2, i32 2} 87 88int main(int argc, const char *argv[]) { 89 A *a = [[A alloc] init]; 90 NSArray *array = [NSArray arrayWithObjects: @"0", @"1", (void*)0]; 91 [A foreach: array]; 92 return 0; 93} 94