Justin Bogner | 52a6a97 | 2014-03-11 04:37:49 +0000 | [diff] [blame] | 1 | // Test instrumentation of C++ exception handling constructs. |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 2 | |
NAKAMURA Takumi | f0f8217 | 2014-01-07 00:59:39 +0000 | [diff] [blame] | 3 | // FIXME: Don't seek bb labels, like "if.else" |
| 4 | // REQUIRES: asserts |
| 5 | |
Sean Silva | 1e51ac2 | 2016-04-23 02:11:16 +0000 | [diff] [blame] | 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 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 8 | |
Justin Bogner | 534f14a | 2014-04-17 22:49:06 +0000 | [diff] [blame] | 9 | // RUN: llvm-profdata merge %S/Inputs/cxx-throws.proftext -o %t.profdata |
Sean Silva | 1e51ac2 | 2016-04-23 02:11:16 +0000 | [diff] [blame] | 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 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 12 | |
Xinliang David Li | ddbdb1e | 2015-12-15 00:33:12 +0000 | [diff] [blame] | 13 | // 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 Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 16 | |
| 17 | // PGOGEN-LABEL: @_Z6throwsv() |
| 18 | // PGOUSE-LABEL: @_Z6throwsv() |
| 19 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 0 |
| 20 | void 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 Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 25 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 3 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 26 | // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]] |
| 27 | if (i % 3) { |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 28 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 4 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 29 | // 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 Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 39 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 5 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 40 | // 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 Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 48 | // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 6 |
| 49 | // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 7 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 50 | // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]] |
| 51 | if (e) {} |
| 52 | } |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 53 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 2 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 54 | |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 55 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 8 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 56 | // 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 Bogner | 097f1bf | 2015-04-28 06:55:23 +0000 | [diff] [blame] | 64 | // PGOGEN-LABEL: @_Z11unreachablei(i32 |
| 65 | // PGOUSE-LABEL: @_Z11unreachablei(i32 |
Justin Bogner | f959feb | 2015-04-28 06:31:55 +0000 | [diff] [blame] | 66 | // PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 0 |
| 67 | void 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 Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 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} |
Justin Bogner | f959feb | 2015-04-28 06:31:55 +0000 | [diff] [blame] | 85 | // PGOUSE-DAG: ![[UN1]] = !{!"branch_weights", i32 2, i32 1} |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 86 | |
| 87 | int main(int argc, const char *argv[]) { |
| 88 | throws(); |
Justin Bogner | f959feb | 2015-04-28 06:31:55 +0000 | [diff] [blame] | 89 | try { |
| 90 | unreachable(1); |
| 91 | } catch (int) {} |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 92 | return 0; |
| 93 | } |