]> gcc.gnu.org Git - gcc.git/blob - gcc/testsuite/gcc.dg/simulate-thread/speculative-store-3.c
re PR middle-end/92046 (Command line options (that are per-functions) are affecting...
[gcc.git] / gcc / testsuite / gcc.dg / simulate-thread / speculative-store-3.c
1 /* { dg-do link } */
2 /* { dg-options "-fno-allow-store-data-races -O2" } */
3 /* { dg-final { simulate-thread } } */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 #include "simulate-thread.h"
9
10 /* Test distilled from PR52558. */
11
12 int g_1 = 1;
13 int g_2 = 0, insns = 0;
14 int f;
15
16 /* Test that g_2 is not written to unless !g_1. */
17
18 __attribute__((noinline))
19 int funky()
20 {
21 int l;
22 for (l = 0; l != 4; l++)
23 {
24 if (g_1)
25 {
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;
30 }
31 for (g_2 = 0; g_2 >= 26; ++g_2)
32 ;
33 }
34 return 999;
35 }
36
37 int simulate_thread_final_verify ()
38 {
39 /* If g_2 != insns, someone must have cached `g_2' and stored a
40 racy value into it. */
41 if (g_2 != insns)
42 {
43 printf("FAIL: g_2 was incorrectly cached\n");
44 return 1;
45 }
46 return 0;
47 }
48
49 void simulate_thread_other_threads ()
50 {
51 ++insns;
52 ++g_2;
53 }
54
55 int simulate_thread_step_verify ()
56 {
57 return 0;
58 }
59
60 __attribute__((noinline))
61 void simulate_thread_main()
62 {
63 f = funky();
64 }
65
66 int main()
67 {
68 simulate_thread_main ();
69 simulate_thread_done ();
70 return 0;
71 }
This page took 0.036707 seconds and 5 git commands to generate.