| 1 | // The waiting loop never exits via the normal |
| 2 | // path before the profile is dumped and the |
| 3 | // program is terminated. This tests checks |
| 4 | // that the entry of main is properly instrumented |
| 5 | // and has non-zero count. |
| 6 | |
| 7 | // RUN: %clang_pgogen -mllvm -do-counter-promotion=false -O2 -o %t %s |
| 8 | // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t |
| 9 | // RUN: llvm-profdata show -function main -counts %t.profraw| FileCheck %s |
| 10 | void exit(int); |
| 11 | |
| 12 | int __llvm_profile_dump(void); |
| 13 | void __llvm_profile_reset_counters(void); |
| 14 | |
| 15 | int g = 0; |
| 16 | __attribute__((noinline)) void doSth() { |
| 17 | g++; |
| 18 | |
| 19 | if (g > 10000) { |
| 20 | // dump profile and exit; |
| 21 | __llvm_profile_dump(); |
| 22 | exit(0); |
| 23 | } |
| 24 | } |
| 25 | int errorcode = 0; |
| 26 | int noerror() { return (errorcode == 0); } |
| 27 | |
| 28 | int main(int argc, const char *argv[]) { |
| 29 | // waiting_loop |
| 30 | while (noerror()) { |
| 31 | doSth(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | // CHECK-LABEL: main |
| 36 | // CHECK: [10001, 1] |
| 37 | |