Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/c-c++-common/simulate-thread/bitfields-1.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* { dg-do link } */ | |
2 /* { dg-options "--param allow-store-data-races=0" } */ | |
3 /* { dg-final { simulate-thread } } */ | |
4 | |
5 #include <stdio.h> | |
6 #include "../../gcc.dg/simulate-thread/simulate-thread.h" | |
7 | |
8 /* Test that we don't store past VAR.A. */ | |
9 | |
10 struct S | |
11 { | |
12 volatile unsigned int a : 4; | |
13 unsigned char b; | |
14 unsigned int c : 6; | |
15 } var = { 1, 2, 3 }; | |
16 | |
17 static int global = 0; | |
18 | |
19 /* Called before each instruction, simulating another thread | |
20 executing. */ | |
21 void simulate_thread_other_threads() | |
22 { | |
23 global++; | |
24 var.b = global; | |
25 /* Don't go past the 6 bits var.c can hold. */ | |
26 var.c = global % 64; | |
27 } | |
28 | |
29 /* Called after each instruction. Returns 1 if any inconsistency is | |
30 found, 0 otherwise. */ | |
31 int simulate_thread_step_verify() | |
32 { | |
33 int ret = 0; | |
34 if (var.b != global) | |
35 { | |
36 printf("FAIL: invalid intermediate value for <b>.\n"); | |
37 ret = 1; | |
38 } | |
39 if (var.c != global % 64) | |
40 { | |
41 printf("FAIL: invalid intermediate value for <c>.\n"); | |
42 ret = 1; | |
43 } | |
44 return ret; | |
45 } | |
46 | |
47 /* Called at the end of the program (simulate_thread_fini == 1). Verifies | |
48 the state of the program and returns 1 if any inconsistency is | |
49 found, 0 otherwise. */ | |
50 int simulate_thread_final_verify() | |
51 { | |
52 if (var.a != 12) | |
53 { | |
54 printf("FAIL: invalid final result for <a>.\n"); | |
55 return 1; | |
56 } | |
57 return 0; | |
58 } | |
59 | |
60 __attribute__((noinline)) | |
61 void simulate_thread_main() | |
62 { | |
63 var.a = 12; | |
64 } | |
65 | |
66 int main() | |
67 { | |
68 simulate_thread_main(); | |
69 simulate_thread_done(); | |
70 return 0; | |
71 } |