PR c++/86728 - C variadic generic lambda.
[official-gcc.git] / gcc / testsuite / g++.dg / simulate-thread / bitfields.C
blobb829587276b2f764dfaec927b264777c1e9af4c4
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   /* On x86-64, the volatile causes us to access <a> with a 32-bit
19      access, and thus trigger this test.  */
20   volatile unsigned int a : 4;
22   unsigned char b;
23   unsigned int c : 6;
24 } var;
26 __attribute__((noinline))
27 void set_a()
29   var.a = CONSTA;
32 void simulate_thread_other_threads()
34   ++global;
35   var.b = global;
36   var.c = global;
39 int simulate_thread_step_verify()
41   int ret = 0;
42   if (var.b != global)
43     {
44       printf ("FAIL: Unexpected value: var.b is %d, should be %d\n",
45               var.b, global);
46       ret = 1;
47     }
48   if (var.c != global)
49     {
50       printf ("FAIL: Unexpected value: var.c is %d, should be %d\n",
51               var.c, global);
52       ret = 1;
53     }
54   return ret;
57 int simulate_thread_final_verify()
59   int ret = simulate_thread_step_verify();
60   if (var.a != CONSTA)
61     {
62       printf ("FAIL: Unexpected value: var.a is %d, should be %d\n",
63               var.a, CONSTA);
64       ret = 1;
65     }
66   return ret;
69 __attribute__((noinline))
70 void simulate_thread_main()
72   set_a();
75 int main ()
77   simulate_thread_main();
78   simulate_thread_done();
79   return 0;