aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/c11-atomic-4.c
blob: 81003aa69545d1df092205f0671b1bfba743b5be (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* PR c/69002 */
/* Test we diagnose accessing elements of atomic structures or unions,
   which is undefined behavior (C11 6.5.2.3#5).  */
/* { dg-do compile } */
/* { dg-options "-std=c11 -pedantic-errors" } */

struct S { int x; };
union U { int x; };

int
fn1 (_Atomic struct S p)
{
  int e = 0 && p.x;
  return p.x + e; /* { dg-warning "accessing a member .x. of an atomic structure" } */
}

int
fn2 (_Atomic struct S *p)
{
  int e = 1 || p->x;
  return p->x + e; /* { dg-warning "accessing a member .x. of an atomic structure" } */
}

void
fn3 (_Atomic struct S p, int x)
{
  p.x = x; /* { dg-warning "accessing a member .x. of an atomic structure" } */
}

void
fn4 (_Atomic struct S *p, int x)
{
  p->x = x; /* { dg-warning "accessing a member .x. of an atomic structure" } */
}

int
fn5 (_Atomic struct S p)
{
  /* This is OK: Members can be safely accessed using a non-atomic
     object which is assigned to or from the atomic object.  */
  struct S s = p;
  return s.x;
}

int
fn6 (_Atomic struct S *p)
{
  struct S s = *p;
  return s.x;
}

int
fn7 (_Atomic union U p)
{
  int e = 0 && p.x;
  return p.x + e; /* { dg-warning "accessing a member .x. of an atomic union" } */
}

int
fn8 (_Atomic union U *p)
{
  int e = 1 || p->x;
  return p->x + e; /* { dg-warning "accessing a member .x. of an atomic union" } */
}

void
fn9 (_Atomic union U p, int x)
{
  p.x = x; /* { dg-warning "accessing a member .x. of an atomic union" } */
}

void
fn10 (_Atomic union U *p, int x)
{
  p->x = x; /* { dg-warning "accessing a member .x. of an atomic union" } */
}

int
fn11 (_Atomic union U p)
{
  /* This is OK: Members can be safely accessed using a non-atomic
     object which is assigned to or from the atomic object.  */
  union U s = p;
  return s.x;
}

int
fn12 (_Atomic union U *p)
{
  union U s = *p;
  return s.x;
}