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