Update ChangeLog and version files for release
[official-gcc.git] / gcc / testsuite / c-c++-common / tsan / pr65400-1.c
blob96fbbfd36b62629933c605a95be5e264e54a6f83
1 /* PR sanitizer/65400 */
2 /* { dg-shouldfail "tsan" } */
3 /* { dg-additional-options "-fno-omit-frame-pointer -ldl" } */
4 /* { dg-additional-sources pr65400-2.c } */
6 #include <pthread.h>
7 #include "tsan_barrier.h"
9 static pthread_barrier_t barrier;
10 int v;
11 int q;
12 int o;
13 extern void baz4 (int *);
15 __attribute__((noinline, noclone)) int
16 bar (int x)
18 q += x;
19 return x;
22 void
23 foo (int *x)
25 if (__builtin_expect (x == 0, 1))
26 return;
27 bar (bar (bar (bar (*x))));
30 __attribute__((noinline, noclone)) void
31 baz1 (int *x)
33 foo (x);
36 __attribute__((noinline, noclone)) void
37 baz2 (int **x)
39 foo (*x);
42 __attribute__((noinline, noclone)) void
43 baz3 (void)
45 barrier_wait (&barrier);
46 v++;
49 __attribute__((noinline, noclone)) void
50 baz5 (void)
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 ();
64 __attribute__((noinline, noclone)) void *
65 tf (void *arg)
67 (void) arg;
68 baz5 ();
69 return NULL;
72 int
73 main ()
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;
85 /* { dg-output "WARNING: ThreadSanitizer: data race.*#2 _?tf" } */