(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
tsan/
pr65400-1.c
       1  /* PR sanitizer/65400 */
       2  /* { dg-shouldfail "tsan" } */
       3  /* { dg-additional-options "-fno-omit-frame-pointer -ldl" } */
       4  /* { dg-additional-sources pr65400-2.c } */
       5  
       6  #include <pthread.h>
       7  #include "tsan_barrier.h"
       8  
       9  static pthread_barrier_t barrier;
      10  int v __attribute__((aligned(8)));
      11  int q __attribute__((aligned(8)));
      12  int o __attribute__((aligned(8)));
      13  extern void baz4 (int *);
      14  
      15  __attribute__((noinline, noclone)) int
      16  bar (int x)
      17  {
      18    q += x;
      19    return x;
      20  }
      21  
      22  void
      23  foo (int *x)
      24  {
      25    if (__builtin_expect (x == 0, 1))
      26      return;
      27    bar (bar (bar (bar (*x))));
      28  }
      29  
      30  __attribute__((noinline, noclone)) void
      31  baz1 (int *x)
      32  {
      33    foo (x);
      34  }
      35  
      36  __attribute__((noinline, noclone)) void
      37  baz2 (int **x)
      38  {
      39    foo (*x);
      40  }
      41  
      42  __attribute__((noinline, noclone)) void
      43  baz3 (void)
      44  {
      45    barrier_wait (&barrier);
      46    v++;
      47  }
      48  
      49  __attribute__((noinline, noclone)) void
      50  baz5 (void)
      51  {
      52    int i;
      53    o = 1;
      54    baz1 (&o);
      55    int *p = &o;
      56    baz2 (&p);
      57    for (i = 0; i < 128; i++)
      58      baz4 (&o);
      59    if (q != 130 * 4)
      60      __builtin_abort ();
      61    baz3 ();
      62  }
      63  
      64  __attribute__((noinline, noclone)) void *
      65  tf (void *arg)
      66  {
      67    (void) arg;
      68    baz5 ();
      69    return NULL;
      70  }
      71  
      72  int
      73  main ()
      74  {
      75    pthread_t th;
      76    barrier_init (&barrier, 2);
      77    if (pthread_create (&th, NULL, tf, NULL))
      78      return 0;
      79    v++;
      80    barrier_wait (&barrier);
      81    pthread_join (th, NULL);
      82    return 0;
      83  }
      84  
      85  /* { dg-output "WARNING: ThreadSanitizer: data race.*#2 _?tf" } */