* fi.po: Update.
[official-gcc.git] / gcc / testsuite / g++.dg / simulate-thread / bitfields-2.C
blobbe5d1eae5c421447e3e56a772987c0b4ddd33791
1 /* { dg-do link } */
2 /* { dg-options "--param allow-store-data-races=0" } */
3 /* { dg-final { simulate-thread } } */
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.  */
10 #include <stdio.h>
11 #include "simulate-thread.h"
13 #define CONSTA 12
15 static int global;
16 struct S
18   unsigned int a : 4;
19   unsigned char b;
20   unsigned int c : 6;
21 } var;
23 __attribute__((noinline))
24 void set_a()
26   var.a = CONSTA;
29 void simulate_thread_other_threads()
31   ++global;
32   var.b = global;
33   var.c = global;
36 int simulate_thread_step_verify()
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;
54 int simulate_thread_final_verify()
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;
66 __attribute__((noinline))
67 void simulate_thread_main()
69   set_a();
72 int main()
74   simulate_thread_main();
75   simulate_thread_done();
76   return 0;