Tighten condition in vect/pr85586.c (PR 85654)
[official-gcc.git] / gcc / testsuite / gcc.dg / c11-atomic-4.c
blob81003aa69545d1df092205f0671b1bfba743b5be
1 /* PR c/69002 */
2 /* Test we diagnose accessing elements of atomic structures or unions,
3 which is undefined behavior (C11 6.5.2.3#5). */
4 /* { dg-do compile } */
5 /* { dg-options "-std=c11 -pedantic-errors" } */
7 struct S { int x; };
8 union U { int x; };
10 int
11 fn1 (_Atomic struct S p)
13 int e = 0 && p.x;
14 return p.x + e; /* { dg-warning "accessing a member .x. of an atomic structure" } */
17 int
18 fn2 (_Atomic struct S *p)
20 int e = 1 || p->x;
21 return p->x + e; /* { dg-warning "accessing a member .x. of an atomic structure" } */
24 void
25 fn3 (_Atomic struct S p, int x)
27 p.x = x; /* { dg-warning "accessing a member .x. of an atomic structure" } */
30 void
31 fn4 (_Atomic struct S *p, int x)
33 p->x = x; /* { dg-warning "accessing a member .x. of an atomic structure" } */
36 int
37 fn5 (_Atomic struct S p)
39 /* This is OK: Members can be safely accessed using a non-atomic
40 object which is assigned to or from the atomic object. */
41 struct S s = p;
42 return s.x;
45 int
46 fn6 (_Atomic struct S *p)
48 struct S s = *p;
49 return s.x;
52 int
53 fn7 (_Atomic union U p)
55 int e = 0 && p.x;
56 return p.x + e; /* { dg-warning "accessing a member .x. of an atomic union" } */
59 int
60 fn8 (_Atomic union U *p)
62 int e = 1 || p->x;
63 return p->x + e; /* { dg-warning "accessing a member .x. of an atomic union" } */
66 void
67 fn9 (_Atomic union U p, int x)
69 p.x = x; /* { dg-warning "accessing a member .x. of an atomic union" } */
72 void
73 fn10 (_Atomic union U *p, int x)
75 p->x = x; /* { dg-warning "accessing a member .x. of an atomic union" } */
78 int
79 fn11 (_Atomic union U p)
81 /* This is OK: Members can be safely accessed using a non-atomic
82 object which is assigned to or from the atomic object. */
83 union U s = p;
84 return s.x;
87 int
88 fn12 (_Atomic union U *p)
90 union U s = *p;
91 return s.x;