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