(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
gcov-info-to-gcda.c
       1  /* { dg-do run { target *-*-linux* *-*-gnu* } } */
       2  /* { dg-options "-fprofile-arcs -fprofile-info-section" } */
       3  
       4  #define assert(expr)                                            \
       5    ((expr)                                                       \
       6     ? (void)0                                                    \
       7     : (__builtin_printf ("%s:%i: Assertion `%s' failed.\n",      \
       8                          __FILE__, __LINE__, #expr),             \
       9        __builtin_abort ()))
      10  
      11  struct gcov_info;
      12  
      13  extern void
      14  __gcov_info_to_gcda (const struct gcov_info *__info,
      15  		     void (*__filename_fn) (const char *, void *),
      16  		     void (*__dump_fn) (const void *, unsigned, void *),
      17  		     void *(*__allocate_fn) (unsigned, void *),
      18  		     void *__arg);
      19  
      20  extern void
      21  __gcov_filename_to_gcfn (const char *__filename,
      22  			 void (*__dump_fn) (const void *, unsigned, void *),
      23  			 void *__arg);
      24  
      25  extern const struct gcov_info *my_info;
      26  
      27  static unsigned counter;
      28  
      29  static unsigned counter_after_filename;
      30  
      31  static int check_zero;
      32  
      33  static int check_after_filename;
      34  
      35  static void
      36  dump (const void *d, unsigned n, void *arg)
      37  {
      38    unsigned *m = (unsigned *)arg;
      39    assert (arg == &counter);
      40  
      41    if (*m == 0)
      42    {
      43      const unsigned *u = d;
      44      assert (*u == 0x6763666e);
      45      check_zero = 1;
      46    }
      47    else if (*m == counter_after_filename)
      48    {
      49      const unsigned *u = d;
      50      assert (*u == 0x67636461);
      51      check_after_filename = 1;
      52    }
      53  
      54    *m += n;
      55  }
      56  
      57  static void
      58  filename (const char *f, void *arg)
      59  {
      60    assert (arg == &counter);
      61    assert (__builtin_strstr (f, "gcov-info-to-gcda.c") == 0);
      62    __gcov_filename_to_gcfn (f, dump, arg);
      63    counter_after_filename = counter;
      64  }
      65  
      66  static void *
      67  allocate (unsigned length, void *arg)
      68  {
      69    assert (arg == &counter);
      70    return __builtin_malloc (length);
      71  }
      72  
      73  int main()
      74  {
      75    __asm__ volatile (".set my_info, .LPBX2");
      76    __gcov_info_to_gcda (my_info, filename, dump, allocate, &counter);
      77    assert (counter > 8);
      78    assert (check_zero);
      79    assert (check_after_filename);
      80    return 0;
      81  }