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 | |
Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 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 |
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 |
| 10 | // RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE %s |
| 11 | // RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE-EXC %s |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 12 | |
Duncan P. N. Exon Smith | 9121220 | 2014-05-16 01:24:00 +0000 | [diff] [blame^] | 13 | // PGOGEN: @[[THC:__llvm_profile_counters__Z6throwsv]] = hidden global [9 x i64] zeroinitializer |
| 14 | // PGOGEN-EXC: @[[THC:__llvm_profile_counters__Z6throwsv]] = hidden global [9 x i64] zeroinitializer |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 15 | |
| 16 | // PGOGEN-LABEL: @_Z6throwsv() |
| 17 | // PGOUSE-LABEL: @_Z6throwsv() |
| 18 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 0 |
| 19 | void throws() { |
| 20 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 1 |
| 21 | // PGOUSE: br {{.*}} !prof ![[TH1:[0-9]+]] |
| 22 | for (int i = 0; i < 100; ++i) { |
| 23 | try { |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 24 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 3 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 25 | // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]] |
| 26 | if (i % 3) { |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 27 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 4 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 28 | // PGOUSE: br {{.*}} !prof ![[TH3:[0-9]+]] |
| 29 | if (i < 50) |
| 30 | throw 1; |
| 31 | } else { |
| 32 | // The catch block may be emitted after the throw above, we can skip it |
| 33 | // by looking for an else block, but this will break if anyone puts an |
| 34 | // else in the catch |
| 35 | // PGOUSE: if.else{{.*}}: |
| 36 | // PGOGEN: if.else{{.*}}: |
| 37 | |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 38 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 5 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 39 | // PGOUSE: br {{.*}} !prof ![[TH4:[0-9]+]] |
| 40 | if (i >= 50) |
| 41 | throw 0; |
| 42 | } |
| 43 | } catch (int e) { |
| 44 | // PGOUSE-EXC: catch{{.*}}: |
| 45 | // PGOGEN-EXC: catch{{.*}}: |
| 46 | |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 47 | // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 6 |
| 48 | // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 7 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 49 | // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]] |
| 50 | if (e) {} |
| 51 | } |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 52 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 2 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 53 | |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 54 | // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 8 |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 55 | // PGOUSE: br {{.*}} !prof ![[TH6:[0-9]+]] |
| 56 | if (i < 100) {} |
| 57 | } |
| 58 | |
| 59 | // PGOUSE-NOT: br {{.*}} !prof ![0-9]+ |
| 60 | // PGOUSE: ret void |
| 61 | } |
| 62 | |
| 63 | // PGOUSE-DAG: ![[TH1]] = metadata !{metadata !"branch_weights", i32 101, i32 2} |
| 64 | // PGOUSE-DAG: ![[TH2]] = metadata !{metadata !"branch_weights", i32 67, i32 35} |
| 65 | // PGOUSE-DAG: ![[TH3]] = metadata !{metadata !"branch_weights", i32 34, i32 34} |
| 66 | // PGOUSE-DAG: ![[TH4]] = metadata !{metadata !"branch_weights", i32 18, i32 18} |
| 67 | // PGOUSE-EXC: ![[TH5]] = metadata !{metadata !"branch_weights", i32 34, i32 18} |
| 68 | // PGOUSE-DAG: ![[TH6]] = metadata !{metadata !"branch_weights", i32 101, i32 1} |
| 69 | |
| 70 | int main(int argc, const char *argv[]) { |
| 71 | throws(); |
| 72 | return 0; |
| 73 | } |