xref: /aosp_15_r20/external/compiler-rt/test/profile/Inputs/instrprof-merge-match-lib.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot #include <stdint.h>
2*7c3d14c8STreehugger Robot #include <stdio.h>
3*7c3d14c8STreehugger Robot #include <stdlib.h>
4*7c3d14c8STreehugger Robot 
5*7c3d14c8STreehugger Robot int __llvm_profile_runtime = 0;
6*7c3d14c8STreehugger Robot uint64_t __llvm_profile_get_size_for_buffer(void);
7*7c3d14c8STreehugger Robot int __llvm_profile_write_buffer(char *);
8*7c3d14c8STreehugger Robot void __llvm_profile_reset_counters(void);
9*7c3d14c8STreehugger Robot int __llvm_profile_check_compatibility(const char *, uint64_t);
10*7c3d14c8STreehugger Robot 
11*7c3d14c8STreehugger Robot int gg = 0;
bar(char c)12*7c3d14c8STreehugger Robot void bar(char c) {
13*7c3d14c8STreehugger Robot   if (c == '1')
14*7c3d14c8STreehugger Robot     gg++;
15*7c3d14c8STreehugger Robot   else
16*7c3d14c8STreehugger Robot     gg--;
17*7c3d14c8STreehugger Robot }
18*7c3d14c8STreehugger Robot 
19*7c3d14c8STreehugger Robot /* Returns 0 (size) when an error occurs. */
libEntry(char * Buffer,uint64_t MaxSize)20*7c3d14c8STreehugger Robot uint64_t libEntry(char *Buffer, uint64_t MaxSize) {
21*7c3d14c8STreehugger Robot 
22*7c3d14c8STreehugger Robot   uint64_t Size = __llvm_profile_get_size_for_buffer();
23*7c3d14c8STreehugger Robot   if (Size > MaxSize)
24*7c3d14c8STreehugger Robot     return 0;
25*7c3d14c8STreehugger Robot 
26*7c3d14c8STreehugger Robot   __llvm_profile_reset_counters();
27*7c3d14c8STreehugger Robot 
28*7c3d14c8STreehugger Robot   bar('1');
29*7c3d14c8STreehugger Robot 
30*7c3d14c8STreehugger Robot   if (__llvm_profile_write_buffer(Buffer))
31*7c3d14c8STreehugger Robot     return 0;
32*7c3d14c8STreehugger Robot 
33*7c3d14c8STreehugger Robot   /* Now check compatibility. Should return 0.  */
34*7c3d14c8STreehugger Robot   if (__llvm_profile_check_compatibility(Buffer, Size))
35*7c3d14c8STreehugger Robot     return 0;
36*7c3d14c8STreehugger Robot 
37*7c3d14c8STreehugger Robot   return Size;
38*7c3d14c8STreehugger Robot }
39*7c3d14c8STreehugger Robot 
40