(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.c-torture/
execute/
pr34456.c
       1  /* { dg-skip-if "requires qsort" { freestanding } }  */
       2  
       3  #include <stdlib.h>
       4  
       5  int __attribute__ ((noinline)) debug (void) { return 1; }
       6  int errors;
       7  
       8  struct s { int elt; int (*compare) (int); };
       9  
      10  static int
      11  compare (const void *x, const void *y)
      12  {
      13    const struct s *s1 = x, *s2 = y;
      14    int (*compare1) (int);
      15    int elt2;
      16  
      17    compare1 = s1->compare;
      18    elt2 = s2->elt;
      19    if (elt2 != 0 && debug () && compare1 (s1->elt) != 0)
      20      errors++;
      21    return compare1 (elt2);
      22  }
      23  
      24  int bad_compare (int x) { return -x; }
      25  struct s array[2] = { { 1, bad_compare }, { -1, bad_compare } };
      26  
      27  int
      28  main (void)
      29  {
      30    qsort (array, 2, sizeof (struct s), compare);
      31    return errors == 0;
      32  }