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