libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / simulate-thread / speculative-store.c
blob7afaabb150e22f68ec78f437dabf6032dc77cab5
1 /* { dg-do link } */
2 /* { dg-options "-fno-allow-store-data-races" } */
3 /* { dg-final { simulate-thread } } */
5 #include <stdio.h>
6 #include "simulate-thread.h"
8 /* This file tests that speculative store movement out of a loop doesn't
9 happen. This is disallowed when -fno-allow-store-data-races. */
11 int global = 100;
13 /* Other thread makes sure global is 100 before the next instruction is
14 * exceuted. */
15 void simulate_thread_other_threads()
17 global = 100;
20 int simulate_thread_step_verify()
22 if (global != 100)
24 printf("FAIL: global variable was assigned to. \n");
25 return 1;
27 return 0;
30 int simulate_thread_final_verify()
32 return 0;
35 /* The variable global should never be assigned if func(0) is called.
36 This tests store movement out of loop thats never executed. */
37 void test (int y)
39 int x;
40 for (x=0; x< y; x++)
42 global = y; /* This should never speculatively execute. */
46 __attribute__((noinline))
47 void simulate_thread_main()
49 test(0);
50 simulate_thread_done();
53 __attribute__((noinline))
54 int main()
56 simulate_thread_main();
57 return 0;