Debian Codegraph @

gcc/testsuite/c-c++-common/simulate-thread/bitfields-4.c

raw
1 /* { dg-do link } */
2 /* { dg-options "-fno-allow-store-data-races" } */
3 /* { dg-final { simulate-thread } } */
4 /* { dg-skip-if "requires hosted libstdc++ for stdlib calloc" { ! hostedlib } } */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "../../gcc.dg/simulate-thread/simulate-thread.h"
9
10 struct bits
11 {
12 char a;
13 int b:7;
14 int c:9;
15 unsigned char d;
16 } *p;
17
18 static int global = 0;
19
20 void simulate_thread_other_threads()
21 {
22 global++;
23 p->d = global % 256;
24 }
25
26 int simulate_thread_step_verify()
27 {
28 if (p->d != global % 256)
29 {
30 printf("FAIL: invalid intermediate result\n");
31 return 1;
32 }
33 return 0;
34 }
35
36 int simulate_thread_final_verify()
37 {
38 if (p->c != 55)
39 {
40 printf("FAIL: invalid final result\n");
41 return 1;
42 }
43 return 0;
44 }
45
46 /* Store into <c> should not clobber <d>. */
47 /* We should not use a 32-bit move to store into p->, but a smaller move. */
48 __attribute__((noinline))
49 void simulate_thread_main()
50 {
51 p -> c = 55;
52 }
53
54
55 int main()
56 {
57 p = (struct bits *) calloc (1, sizeof (struct bits));
58 simulate_thread_main();
59 simulate_thread_done();
60 return 0;
61 }