blob: ef56c8b28801e6e3e6ceb4a173b9ee5cf4663a21 [file] [log] [blame]
Justin Bogner52a6a972014-03-11 04:37:49 +00001// Test instrumentation of C++ exception handling constructs.
Justin Bogneref512b92014-01-06 22:27:43 +00002
NAKAMURA Takumif0f82172014-01-07 00:59:39 +00003// FIXME: Don't seek bb labels, like "if.else"
4// REQUIRES: asserts
5
Sean Silva1e51ac22016-04-23 02:11:16 +00006// 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
Justin Bogneref512b92014-01-06 22:27:43 +00008
Justin Bogner534f14a2014-04-17 22:49:06 +00009// RUN: llvm-profdata merge %S/Inputs/cxx-throws.proftext -o %t.profdata
Sean Silva1e51ac22016-04-23 02:11:16 +000010// 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
Justin Bogneref512b92014-01-06 22:27:43 +000012
Xinliang David Liddbdb1e2015-12-15 00:33:12 +000013// PGOGEN: @[[THC:__profc__Z6throwsv]] = private global [9 x i64] zeroinitializer
14// PGOGEN-EXC: @[[THC:__profc__Z6throwsv]] = private global [9 x i64] zeroinitializer
15// PGOGEN: @[[UNC:__profc__Z11unreachablei]] = private global [3 x i64] zeroinitializer
Justin Bogneref512b92014-01-06 22:27:43 +000016
17// PGOGEN-LABEL: @_Z6throwsv()
18// PGOUSE-LABEL: @_Z6throwsv()
19// PGOGEN: store {{.*}} @[[THC]], i64 0, i64 0
20void throws() {
21 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 1
22 // PGOUSE: br {{.*}} !prof ![[TH1:[0-9]+]]
23 for (int i = 0; i < 100; ++i) {
24 try {
Bob Wilsonbf854f02014-02-17 19:21:09 +000025 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 3
Justin Bogneref512b92014-01-06 22:27:43 +000026 // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]]
27 if (i % 3) {
Bob Wilsonbf854f02014-02-17 19:21:09 +000028 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 4
Justin Bogneref512b92014-01-06 22:27:43 +000029 // PGOUSE: br {{.*}} !prof ![[TH3:[0-9]+]]
30 if (i < 50)
31 throw 1;
32 } else {
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
35 // else in the catch
36 // PGOUSE: if.else{{.*}}:
37 // PGOGEN: if.else{{.*}}:
38
Bob Wilsonbf854f02014-02-17 19:21:09 +000039 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 5
Justin Bogneref512b92014-01-06 22:27:43 +000040 // PGOUSE: br {{.*}} !prof ![[TH4:[0-9]+]]
41 if (i >= 50)
42 throw 0;
43 }
44 } catch (int e) {
45 // PGOUSE-EXC: catch{{.*}}:
46 // PGOGEN-EXC: catch{{.*}}:
47
Bob Wilsonbf854f02014-02-17 19:21:09 +000048 // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 6
49 // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 7
Justin Bogneref512b92014-01-06 22:27:43 +000050 // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]]
51 if (e) {}
52 }
Bob Wilsonbf854f02014-02-17 19:21:09 +000053 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 2
Justin Bogneref512b92014-01-06 22:27:43 +000054
Bob Wilsonbf854f02014-02-17 19:21:09 +000055 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 8
Justin Bogneref512b92014-01-06 22:27:43 +000056 // PGOUSE: br {{.*}} !prof ![[TH6:[0-9]+]]
57 if (i < 100) {}
58 }
59
60 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
61 // PGOUSE: ret void
62}
63
Justin Bogner097f1bf2015-04-28 06:55:23 +000064// PGOGEN-LABEL: @_Z11unreachablei(i32
65// PGOUSE-LABEL: @_Z11unreachablei(i32
Justin Bognerf959feb2015-04-28 06:31:55 +000066// PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 0
67void unreachable(int i) {
68 // PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 1
69 // PGOUSE: br {{.*}} !prof ![[UN1:[0-9]+]]
70 if (i)
71 throw i;
72
73 // PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 2
74 // Since we never reach here, the weights should all be zero (and skipped)
75 // PGOUSE-NOT: br {{.*}} !prof !{{.*}}
76 if (i) {}
77}
78
Duncan P. N. Exon Smithb3a66692014-12-15 19:10:08 +000079// 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}
Justin Bognerf959feb2015-04-28 06:31:55 +000085// PGOUSE-DAG: ![[UN1]] = !{!"branch_weights", i32 2, i32 1}
Justin Bogneref512b92014-01-06 22:27:43 +000086
87int main(int argc, const char *argv[]) {
88 throws();
Justin Bognerf959feb2015-04-28 06:31:55 +000089 try {
90 unreachable(1);
91 } catch (int) {}
Justin Bogneref512b92014-01-06 22:27:43 +000092 return 0;
93}