1 // Test instrumentation of general constructs in objective C.
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
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
8 // PGOUSE-NOT: warning: profile data may be out of date
10 #ifdef HAVE_FOUNDATION
12 // Use this to build an instrumented version to regenerate the input file.
13 #import <Foundation/Foundation.h>
17 // Minimal definitions to get this to compile without Foundation.h.
22 @interface NSObject <NSObject>
27 struct NSFastEnumerationState;
28 @interface NSArray : NSObject
29 - (unsigned long) countByEnumeratingWithState: (struct NSFastEnumerationState*) state
31 count: (unsigned long) bufferSize;
32 +(NSArray*) arrayWithObjects: (id) first, ...;
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
40 @interface A : NSObject
41 + (void)foreach: (NSArray *)array;
45 // PGOGEN: define {{.*}}+[A foreach:]
46 // PGOUSE: define {{.*}}+[A foreach:]
47 // PGOGEN: store {{.*}} @[[FRC]]
48 + (void)foreach: (NSArray *)array
51 // PGOGEN: store {{.*}} @[[FRC]], i32 0, i32 1
52 // PGOUSE: br {{.*}} !prof ![[FR1:[0-9]+]]
53 // PGOUSE: br {{.*}} !prof ![[FR2:[0-9]+]]
55 // PGOGEN: define {{.*}}_block_invoke
56 // PGOUSE: define {{.*}}_block_invoke
57 // PGOGEN: store {{.*}} @[[BLC]]
60 // PGOGEN: store {{.*}} @[[BLC]], i32 0, i32 1
61 // PGOUSE: br {{.*}} !prof ![[BL1:[0-9]+]]
70 void nested_objc_for_ranges(NSArray *arr) {
77 void consecutive_objc_for_ranges(NSArray *arr) {
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}
88 int main(int argc, const char *argv[]) {
89 A *a = [[A alloc] init];
90 NSArray *array = [NSArray arrayWithObjects: @"0", @"1", (void*)0];