1 // Test instrumentation of C++ exception handling constructs.
3 // FIXME: Don't seek bb labels, like "if.else"
6 // RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument=clang -fexceptions -fcxx-exceptions -triple %itanium_abi_triple | FileCheck -check-prefix=PGOGEN %s
7 // RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument=clang -fexceptions -fcxx-exceptions -triple %itanium_abi_triple | FileCheck -check-prefix=PGOGEN-EXC %s
9 // RUN: llvm-profdata merge %S/Inputs/cxx-throws.proftext -o %t.profdata
10 // RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -fexceptions -fcxx-exceptions -triple %itanium_abi_triple | FileCheck -check-prefix=PGOUSE %s
11 // RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -fexceptions -fcxx-exceptions -triple %itanium_abi_triple | FileCheck -check-prefix=PGOUSE-EXC %s
13 // PGOGEN: @[[THC:__profc__Z6throwsv]] = {{(private|internal)}} global [9 x i64] zeroinitializer
14 // PGOGEN-EXC: @[[THC:__profc__Z6throwsv]] = {{(private|internal)}} global [9 x i64] zeroinitializer
15 // PGOGEN: @[[UNC:__profc__Z11unreachablei]] = {{(private|internal)}} global [3 x i64] zeroinitializer
17 // PGOGEN-LABEL: @_Z6throwsv()
18 // PGOUSE-LABEL: @_Z6throwsv()
19 // PGOGEN: store {{.*}} @[[THC]]
21 // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 1
22 // PGOUSE: br {{.*}} !prof ![[TH1:[0-9]+]]
23 for (int i
= 0; i
< 100; ++i
) {
25 // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 3
26 // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]]
28 // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 4
29 // PGOUSE: br {{.*}} !prof ![[TH3:[0-9]+]]
33 // The catch block may be emitted after the throw above, we can skip it
34 // by looking for an else block, but this will break if anyone puts an
36 // PGOUSE: if.else{{.*}}:
37 // PGOGEN: if.else{{.*}}:
39 // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 5
40 // PGOUSE: br {{.*}} !prof ![[TH4:[0-9]+]]
45 // PGOUSE-EXC: catch{{.*}}:
46 // PGOGEN-EXC: catch{{.*}}:
48 // PGOGEN-EXC: store {{.*}} @[[THC]], i32 0, i32 6
49 // PGOGEN-EXC: store {{.*}} @[[THC]], i32 0, i32 7
50 // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]]
53 // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 2
55 // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 8
56 // PGOUSE: br {{.*}} !prof ![[TH6:[0-9]+]]
60 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
64 // PGOGEN-LABEL: @_Z11unreachablei(i32
65 // PGOUSE-LABEL: @_Z11unreachablei(i32
66 // PGOGEN: store {{.*}} @[[UNC]]
67 void unreachable(int i
) {
68 // PGOGEN: store {{.*}} @[[UNC]], i32 0, i32 1
69 // PGOUSE: br {{.*}} !prof ![[UN1:[0-9]+]]
73 // PGOGEN: store {{.*}} @[[UNC]], i32 0, i32 2
74 // Since we never reach here, the weights should all be zero (and skipped)
75 // PGOUSE-NOT: br {{.*}} !prof !{{.*}}
79 // PGOUSE-DAG: ![[TH1]] = !{!"branch_weights", i32 101, i32 2}
80 // PGOUSE-DAG: ![[TH2]] = !{!"branch_weights", i32 67, i32 35}
81 // PGOUSE-DAG: ![[TH3]] = !{!"branch_weights", i32 34, i32 34}
82 // PGOUSE-DAG: ![[TH4]] = !{!"branch_weights", i32 18, i32 18}
83 // PGOUSE-EXC: ![[TH5]] = !{!"branch_weights", i32 34, i32 18}
84 // PGOUSE-DAG: ![[TH6]] = !{!"branch_weights", i32 101, i32 1}
85 // PGOUSE-DAG: ![[UN1]] = !{!"branch_weights", i32 2, i32 1}
87 int main(int argc
, const char *argv
[]) {