PR tree-optimization/84740
[official-gcc.git] / gcc / testsuite / gcc.dg / simulate-thread / speculative-store-3.c
blob203c026048d4be65e6ee22756c69559fb5cf65ab
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 distilled from PR52558. */
12 int g_1 = 1;
13 int g_2 = 0, insns = 0;
14 int f;
16 /* Test that g_2 is not written to unless !g_1. */
18 __attribute__((noinline))
19 int funky()
21 int l;
22 for (l = 0; l != 4; l++)
24 if (g_1)
26 /* g_1 is globally true so we should always execute here,
27 thus never writing to g_2 under any circumstance in this
28 code path. */
29 return l;
31 for (g_2 = 0; g_2 >= 26; ++g_2)
34 return 999;
37 int simulate_thread_final_verify ()
39 /* If g_2 != insns, someone must have cached `g_2' and stored a
40 racy value into it. */
41 if (g_2 != insns)
43 printf("FAIL: g_2 was incorrectly cached\n");
44 return 1;
46 return 0;
49 void simulate_thread_other_threads ()
51 ++insns;
52 ++g_2;
55 int simulate_thread_step_verify ()
57 return 0;
60 __attribute__((noinline))
61 void simulate_thread_main()
63 f = funky();
66 int main()
68 simulate_thread_main ();
69 simulate_thread_done ();
70 return 0;