Debian Codegraph @

gcc/testsuite/g++.dg/simulate-thread/bitfields-2.C

raw
1 /* { dg-do link } */
2 /* { dg-options "-fno-allow-store-data-races" } */
3 /* { dg-final { simulate-thread } } */
4
5 /* Test that setting <var.a> does not touch either <var.b> or <var.c>.
6 In the C++ memory model, non contiguous bitfields ("a" and "c"
7 here) should be considered as distinct memory locations, so we
8 can't use bit twiddling to set either one. */
9
10 #include <stdio.h>
11 #include "simulate-thread.h"
12
13 #define CONSTA 12
14
15 static int global;
16 struct S
17 {
18 unsigned int a : 4;
19 unsigned char b;
20 unsigned int c : 6;
21 } var;
22
23 __attribute__((noinline))
24 void set_a()
25 {
26 var.a = CONSTA;
27 }
28
29 void simulate_thread_other_threads()
30 {
31 ++global;
32 var.b = global;
33 var.c = global;
34 }
35
36 int simulate_thread_step_verify()
37 {
38 int ret = 0;
39 if (var.b != global)
40 {
41 printf ("FAIL: Unexpected value: var.b is %d, should be %d\n",
42 var.b, global);
43 ret = 1;
44 }
45 if (var.c != global)
46 {
47 printf ("FAIL: Unexpected value: var.c is %d, should be %d\n",
48 var.c, global);
49 ret = 1;
50 }
51 return ret;
52 }
53
54 int simulate_thread_final_verify()
55 {
56 int ret = simulate_thread_step_verify();
57 if (var.a != CONSTA)
58 {
59 printf ("FAIL: Unexpected value: var.a is %d, should be %d\n",
60 var.a, CONSTA);
61 ret = 1;
62 }
63 return ret;
64 }
65
66 __attribute__((noinline))
67 void simulate_thread_main()
68 {
69 set_a();
70 }
71
72 int main()
73 {
74 simulate_thread_main();
75 simulate_thread_done();
76 return 0;
77 }