1// RUN: %clang_pgogen -mllvm -pgo-block-coverage %s -o %t.out
2// RUN: env LLVM_PROFILE_FILE=%t1.profraw %run %t.out 1
3// RUN: env LLVM_PROFILE_FILE=%t2.profraw %run %t.out 2
4// RUN: llvm-profdata merge -o %t.profdata %t1.profraw %t2.profraw
5// RUN: %clang_profuse=%t.profdata -mllvm -pgo-verify-bfi -o - -S -emit-llvm %s 2>%t.errs | FileCheck %s --implicit-check-not="!prof"
6// RUN: FileCheck %s < %t.errs --allow-empty --check-prefix=CHECK-ERROR
7
8// RUN: llvm-profdata merge -o %t2.profdata %t1.profraw %t1.profraw %t2.profraw %t2.profraw
9// RUN: llvm-profdata show %t2.profdata | FileCheck %s --check-prefix=COUNTS
10
11#include <stdlib.h>
12
13// CHECK: @foo({{.*}})
14// CHECK-SAME: !prof ![[PROF0:[0-9]+]]
15void foo(int a) {
16 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PROF1:[0-9]+]]
17 if (a % 2 == 0) {
18 //
19 } else {
20 //
21 }
22
23 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PROF1]]
24 for (int i = 1; i < a; i++) {
25 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PROF2:[0-9]+]]
26 if (a % 3 == 0) {
27 //
28 } else {
29 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PROF2]]
30 if (a % 1001 == 0) {
31 return;
32 }
33 }
34 }
35
36 return;
37}
38
39// CHECK: @main({{.*}})
40// CHECK-SAME: !prof ![[PROF0]]
41int main(int argc, char *argv[]) {
42 foo(a: atoi(nptr: argv[1]));
43 return 0;
44}
45
46// CHECK-DAG: ![[PROF0]] = !{!"function_entry_count", i64 10000}
47// CHECK-DAG: ![[PROF1]] = !{!"branch_weights", i32 1, i32 1}
48// CHECK-DAG: ![[PROF2]] = !{!"branch_weights", i32 0, i32 1}
49
50// CHECK-ERROR-NOT: warning: {{.*}}: Found inconsistent block coverage
51
52// COUNTS: Maximum function count: 4
53

source code of compiler-rt/test/profile/instrprof-block-coverage.c