PR middle-end/77357 - strlen of constant strings not folded
[official-gcc.git] / gcc / testsuite / gcc.dg / simulate-thread / speculative-store-2.c
blobd4d28f5ed6078238519b8aa13c4a13a486be557a
1 /* { dg-do link } */
2 /* { dg-options "--param allow-store-data-races=0 -O2" } */
3 /* { dg-final { simulate-thread } } */
5 #include <stdio.h>
6 #include <stdlib.h>
8 #include "simulate-thread.h"
10 /* Test that speculative stores do not happen for --param
11 allow-store-data-races=0. */
13 int count, insns;
15 struct obj {
16 int data;
17 struct obj *next;
18 } *q;
20 void simulate_thread_other_threads ()
22 ++insns;
23 ++count;
26 int simulate_thread_step_verify ()
28 return 0;
31 int simulate_thread_final_verify ()
33 /* If count != insns, someone must have cached `count' and stored a
34 racy value into it. */
35 if (count != insns)
37 printf("FAIL: count was incorrectly cached\n");
38 return 1;
40 return 0;
43 /* Test that `count' is not written to unless p->data > 0. */
45 __attribute__((noinline))
46 void simulate_thread_main()
48 struct obj *p;
49 for (p = q; p; p = p->next)
50 if (p->data > 0)
51 count++;
54 struct obj *
55 insert(struct obj *head, int data)
57 struct obj *t = (struct obj *) malloc (sizeof (struct obj));
58 t->next = head;
59 t->data = data;
60 return t;
63 int main()
65 q = insert (0, 0);
66 q = insert (q, 0);
67 q = insert (q, 0);
68 q = insert (q, 0);
69 q = insert (q, 0);
71 simulate_thread_main ();
72 simulate_thread_done ();
73 return 0;