brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · fc04add Raw
94 lines · cpp
1// Test instrumentation of C++ exception handling constructs.2 3// FIXME: Don't seek bb labels, like "if.else"4// REQUIRES: asserts5 6// RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument=clang -fexceptions -fcxx-exceptions -triple %itanium_abi_triple | FileCheck -check-prefix=PGOGEN %s7// RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument=clang -fexceptions -fcxx-exceptions -triple %itanium_abi_triple | FileCheck -check-prefix=PGOGEN-EXC %s8 9// RUN: llvm-profdata merge %S/Inputs/cxx-throws.proftext -o %t.profdata10// RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata -fexceptions -fcxx-exceptions -triple %itanium_abi_triple | FileCheck -check-prefix=PGOUSE %s11// RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata -fexceptions -fcxx-exceptions -triple %itanium_abi_triple | FileCheck -check-prefix=PGOUSE-EXC %s12 13// PGOGEN: @[[THC:__profc__Z6throwsv]] = {{(private|internal)}} global [9 x i64] zeroinitializer14// PGOGEN-EXC: @[[THC:__profc__Z6throwsv]] = {{(private|internal)}} global [9 x i64] zeroinitializer15// PGOGEN: @[[UNC:__profc__Z11unreachablei]] = {{(private|internal)}} global [3 x i64] zeroinitializer16 17// PGOGEN-LABEL: @_Z6throwsv()18// PGOUSE-LABEL: @_Z6throwsv()19// PGOGEN: store {{.*}} @[[THC]]20void throws() {21  // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 122  // PGOUSE: br {{.*}} !prof ![[TH1:[0-9]+]]23  for (int i = 0; i < 100; ++i) {24    try {25      // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 326      // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]]27      if (i % 3) {28        // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 429        // 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 it34        // by looking for an else block, but this will break if anyone puts an35        // else in the catch36        // PGOUSE: if.else{{.*}}:37        // PGOGEN: if.else{{.*}}:38 39        // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 540        // 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 48      // PGOGEN-EXC: store {{.*}} @[[THC]], i32 0, i32 649      // PGOGEN-EXC: store {{.*}} @[[THC]], i32 0, i32 750      // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]]51      if (e) {}52    }53    // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 254 55    // PGOGEN: store {{.*}} @[[THC]], i32 0, i32 856    // PGOUSE: br {{.*}} !prof ![[TH6:[0-9]+]]57    if (i < 100) {}58  }59 60  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+61  // PGOUSE: ret void62}63 64// PGOGEN-LABEL: @_Z11unreachablei(i3265// PGOUSE-LABEL: @_Z11unreachablei(i3266// PGOGEN: store {{.*}} @[[UNC]]67void unreachable(int i) {68  // PGOGEN: store {{.*}} @[[UNC]], i32 0, i32 169  // PGOUSE: br {{.*}} !prof ![[UN1:[0-9]+]]70  if (i)71    throw i;72 73  // PGOGEN: store {{.*}} @[[UNC]], i32 0, i32 274  // Since we never reach here, the weights should all be zero (and skipped)75  // PGOUSE-NOT: br {{.*}} !prof !{{.*}}76  if (i) {}77}78 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}86 87int main(int argc, const char *argv[]) {88  throws();89  try {90    unreachable(1);91  } catch (int) {}92  return 0;93}94