(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
asan/
pointer-subtract-3.c
       1  /* { dg-do run { target pthread_h } } */
       2  /* { dg-skip-if "no pthread_barrier" { *-*-darwin* } } */
       3  /* { dg-set-target-env-var ASAN_OPTIONS "detect_invalid_pointer_pairs=2:halt_on_error=1" } */
       4  /* { dg-options "-fsanitize=address,pointer-subtract" } */
       5  /* { dg-additional-options "-pthread" { target pthread } } */
       6  
       7  #include <unistd.h>
       8  #include <pthread.h>
       9  
      10  char *pointers[2];
      11  pthread_barrier_t bar;
      12  
      13  void *
      14  thread_main (void *n)
      15  {
      16    char local;
      17  
      18    __UINTPTR_TYPE__ id = (__UINTPTR_TYPE__) n;
      19    pointers[id] = &local;
      20    pthread_barrier_wait (&bar);
      21    pthread_barrier_wait (&bar);
      22  
      23    return 0;
      24  }
      25  
      26  int
      27  main ()
      28  {
      29    pthread_t threads[2];
      30    pthread_barrier_init (&bar, NULL, 3);
      31    pthread_create (&threads[0], NULL, thread_main, (void *) 0);
      32    pthread_create (&threads[1], NULL, thread_main, (void *) 1);
      33    pthread_barrier_wait (&bar);
      34  
      35    /* This case is not handled yet.  */
      36    volatile __PTRDIFF_TYPE__ r = pointers[0] - pointers[1];
      37  
      38    pthread_barrier_wait (&bar);
      39    pthread_join (threads[0], NULL);
      40    pthread_join (threads[1], NULL);
      41    pthread_barrier_destroy (&bar);
      42  
      43    return 0;
      44  }