1 // Test instrumentation of C++ exception handling constructs. 2 3 // FIXME: Don't seek bb labels, like "if.else" 4 // REQUIRES: asserts 5 6 // RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN %s 7 // RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN-EXC %s 8 9 // RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%S/Inputs/cxx-throws.profdata -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE %s 10 // RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%S/Inputs/cxx-throws.profdata -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE-EXC %s 11 12 // PGOGEN: @[[THC:__llvm_profile_counters__Z6throwsv]] = global [9 x i64] zeroinitializer 13 // PGOGEN-EXC: @[[THC:__llvm_profile_counters__Z6throwsv]] = global [9 x i64] zeroinitializer 14 15 // PGOGEN-LABEL: @_Z6throwsv() 16 // PGOUSE-LABEL: @_Z6throwsv() 17 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 0 18 void throws() { 19 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 1 20 // PGOUSE: br {{.*}} !prof ![[TH1:[0-9]+]] 21 for (int i = 0; i < 100; ++i) { 22 try { 23 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 3 24 // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]] 25 if (i % 3) { 26 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 4 27 // PGOUSE: br {{.*}} !prof ![[TH3:[0-9]+]] 28 if (i < 50) 29 throw 1; 30 } else { 31 // The catch block may be emitted after the throw above, we can skip it 32 // by looking for an else block, but this will break if anyone puts an 33 // else in the catch 34 // PGOUSE: if.else{{.*}}: 35 // PGOGEN: if.else{{.*}}: 36 37 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 5 38 // PGOUSE: br {{.*}} !prof ![[TH4:[0-9]+]] 39 if (i >= 50) 40 throw 0; 41 } 42 } catch (int e) { 43 // PGOUSE-EXC: catch{{.*}}: 44 // PGOGEN-EXC: catch{{.*}}: 45 46 // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 6 47 // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 7 48 // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]] 49 if (e) {} 50 } 51 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 2 52 53 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 8 54 // PGOUSE: br {{.*}} !prof ![[TH6:[0-9]+]] 55 if (i < 100) {} 56 } 57 58 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+ 59 // PGOUSE: ret void 60 } 61 62 // PGOUSE-DAG: ![[TH1]] = metadata !{metadata !"branch_weights", i32 101, i32 2} 63 // PGOUSE-DAG: ![[TH2]] = metadata !{metadata !"branch_weights", i32 67, i32 35} 64 // PGOUSE-DAG: ![[TH3]] = metadata !{metadata !"branch_weights", i32 34, i32 34} 65 // PGOUSE-DAG: ![[TH4]] = metadata !{metadata !"branch_weights", i32 18, i32 18} 66 // PGOUSE-EXC: ![[TH5]] = metadata !{metadata !"branch_weights", i32 34, i32 18} 67 // PGOUSE-DAG: ![[TH6]] = metadata !{metadata !"branch_weights", i32 101, i32 1} 68 69 int main(int argc, const char *argv[]) { 70 throws(); 71 return 0; 72 } 73