| 1 |
/* { dg-do link } */ |
| 2 |
/* { dg-options "-fno-allow-store-data-races" } */ |
| 3 |
/* { dg-final { simulate-thread } } */ |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include "simulate-thread.h" |
| 7 |
|
| 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. */ |
| 10 |
|
| 11 |
int global = 100; |
| 12 |
|
| 13 |
/* Other thread makes sure global is 100 before the next instruction is |
| 14 |
* exceuted. */ |
| 15 |
void simulate_thread_other_threads() |
| 16 |
{ |
| 17 |
global = 100; |
| 18 |
} |
| 19 |
|
| 20 |
int simulate_thread_step_verify() |
| 21 |
{ |
| 22 |
if (global != 100) |
| 23 |
{ |
| 24 |
printf("FAIL: global variable was assigned to. \n"); |
| 25 |
return 1; |
| 26 |
} |
| 27 |
return 0; |
| 28 |
} |
| 29 |
|
| 30 |
int simulate_thread_final_verify() |
| 31 |
{ |
| 32 |
return 0; |
| 33 |
} |
| 34 |
|
| 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) |
| 38 |
{ |
| 39 |
int x; |
| 40 |
for (x=0; x< y; x++) |
| 41 |
{ |
| 42 |
global = y; /* This should never speculatively execute. */ |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
__attribute__((noinline)) |
| 47 |
void simulate_thread_main() |
| 48 |
{ |
| 49 |
test(0); |
| 50 |
simulate_thread_done(); |
| 51 |
} |
| 52 |
|
| 53 |
__attribute__((noinline)) |
| 54 |
int main() |
| 55 |
{ |
| 56 |
simulate_thread_main(); |
| 57 |
return 0; |
| 58 |
} |