Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / profile / instrprof-write-buffer-internal.c
blobd9670f739ca98c3284550255a53c16cdf1ecb50e
1 // UNSUPPORTED: target={{.*windows.*}}
2 // The sanitizer-windows bot is saying:
3 // instrprof-write-buffer-internal.c.tmp.buf.profraw: Invalid instrumentation profile data (file header is corrupt)
5 // RUN: rm -f %t.buf.profraw %t.profraw
6 // RUN: %clang_profgen -w -o %t %s
7 // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t %t.buf.profraw
8 // RUN: llvm-profdata show %t.buf.profraw | FileCheck %s -check-prefix=WRITE-BUFFER
9 // RUN: not llvm-profdata show %t.profraw 2>&1 | FileCheck %s -check-prefix=ALREADY-DUMPED
11 // WRITE-BUFFER: Instrumentation level: Front-end
12 // WRITE-BUFFER: Total functions: 1
13 // WRITE-BUFFER: Maximum function count: 1
14 // WRITE-BUFFER: Maximum internal block count: 0
16 // ALREADY-DUMPED: error: {{.+}}: empty raw profile file
18 #include <stdint.h>
19 #include <stdio.h>
20 #include <stdlib.h>
22 const void *__llvm_profile_begin_data(void);
23 const void *__llvm_profile_end_data(void);
24 const char *__llvm_profile_begin_names(void);
25 const char *__llvm_profile_end_names(void);
26 char *__llvm_profile_begin_counters(void);
27 char *__llvm_profile_end_counters(void);
28 char *__llvm_profile_begin_bitmap(void);
29 char *__llvm_profile_end_bitmap(void);
31 uint64_t __llvm_profile_get_size_for_buffer_internal(
32 const void *DataBegin, const void *DataEnd, const char *CountersBegin,
33 const char *CountersEnd, const char *BitmapBegin, const char *BitmapEnd,
34 const char *NamesBegin, const char *NamesEnd);
36 int __llvm_profile_write_buffer_internal(
37 char *Buffer, const void *DataBegin, const void *DataEnd,
38 const char *CountersBegin, const char *CountersEnd, const char *BitmapBegin,
39 const char *BitmapEnd, const char *NamesBegin, const char *NamesEnd);
41 void __llvm_profile_set_dumped(void);
43 int main(int argc, const char *argv[]) {
44 uint64_t bufsize = __llvm_profile_get_size_for_buffer_internal(
45 __llvm_profile_begin_data(), __llvm_profile_end_data(),
46 __llvm_profile_begin_counters(), __llvm_profile_end_counters(),
47 __llvm_profile_begin_bitmap(), __llvm_profile_end_bitmap(),
48 __llvm_profile_begin_names(), __llvm_profile_end_names());
50 char *buf = malloc(bufsize);
51 int ret = __llvm_profile_write_buffer_internal(
52 buf, __llvm_profile_begin_data(), __llvm_profile_end_data(),
53 __llvm_profile_begin_counters(), __llvm_profile_end_counters(),
54 __llvm_profile_begin_bitmap(), __llvm_profile_end_bitmap(),
55 __llvm_profile_begin_names(), __llvm_profile_end_names());
57 if (ret != 0) {
58 fprintf(stderr, "failed to write buffer");
59 return ret;
62 FILE *f = fopen(argv[1], "w");
63 fwrite(buf, bufsize, 1, f);
64 fclose(f);
65 free(buf);
67 __llvm_profile_set_dumped();
69 return 0;