1 // Test that the specified output merges the profiling data.
2 // Run the program twice so that the counters accumulate.
3 // RUN: %clang -fprofile-instr-generate -fcoverage-mapping -o %t %s
4 // RUN: rm -f %t.merging.profraw %t.merging.profdata
5 // RUN: %run %t %t.merging.profraw
6 // RUN: %run %t %t.merging.profraw
7 // RUN: test -f %t.merging.profraw
8 // RUN: llvm-profdata merge -o %t.merging.profdata %t.merging.profraw
9 // RUN: llvm-cov show -instr-profile %t.merging.profdata %t | FileCheck %s --match-full-lines
10 #include <stdio.h>
11 
12 extern void __llvm_profile_set_file_object(FILE *, int);
13 
main(int argc,const char * argv[])14 int main(int argc, const char *argv[]) {
15   if (argc < 2)
16     return 1;
17 
18   FILE *F = fopen(argv[1], "r+b");
19   if (!F) {
20     // File might not exist, try opening with truncation
21     F = fopen(argv[1], "w+b");
22   }
23   __llvm_profile_set_file_object(F, 1);
24 
25   return 0;
26 }
27 // CHECK:   10|       |#include <stdio.h>
28 // CHECK:   11|       |
29 // CHECK:   12|       |extern void __llvm_profile_set_file_object(FILE *, int);
30 // CHECK:   13|       |
31 // CHECK:   14|      2|int main(int argc, const char *argv[]) {
32 // CHECK:   15|      2|  if (argc < 2)
33 // CHECK:   16|      0|    return 1;
34 // CHECK:   17|       |
35 // CHECK:   18|      2|  FILE *F = fopen(argv[1], "r+b");
36 // CHECK:   19|      2|  if (!F) {
37 // CHECK:   20|       |    // File might not exist, try opening with truncation
38 // CHECK:   21|      1|    F = fopen(argv[1], "w+b");
39 // CHECK:   22|      1|  }
40 // CHECK:   23|      2|  __llvm_profile_set_file_object(F, 1);
41 // CHECK:   24|       |
42 // CHECK:   25|      2|  return 0;
43 // CHECK:   26|      2|}
44