annotate gcc/testsuite/gcc.dg/atomic-fetch-bool.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* PR c/68966 - atomic_fetch_* on atomic_bool not diagnosed
kono
parents:
diff changeset
2 Test to verify that calls to __atomic_fetch_op funcions with a _Bool
kono
parents:
diff changeset
3 argument are rejected. This is necessary because GCC expects that
kono
parents:
diff changeset
4 all initialized _Bool objects have a specific representation and
kono
parents:
diff changeset
5 allowing atomic operations to change it would break the invariant. */
kono
parents:
diff changeset
6 /* { dg-do compile } */
kono
parents:
diff changeset
7 /* { dg-options "-pedantic-errors -std=c11" } */
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 void test_atomic_bool (_Atomic _Bool *a)
kono
parents:
diff changeset
11 {
kono
parents:
diff changeset
12 enum { SEQ_CST = __ATOMIC_SEQ_CST };
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 __atomic_fetch_add (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_fetch_add." } */
kono
parents:
diff changeset
15 __atomic_fetch_sub (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_fetch_sub." } */
kono
parents:
diff changeset
16 __atomic_fetch_and (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_fetch_and." } */
kono
parents:
diff changeset
17 __atomic_fetch_xor (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_fetch_xor." } */
kono
parents:
diff changeset
18 __atomic_fetch_or (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_fetch_or." } */
kono
parents:
diff changeset
19 __atomic_fetch_nand (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_fetch_nand." } */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 __atomic_add_fetch (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_add_fetch." } */
kono
parents:
diff changeset
22 __atomic_sub_fetch (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_sub_fetch." } */
kono
parents:
diff changeset
23 __atomic_and_fetch (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_and_fetch." } */
kono
parents:
diff changeset
24 __atomic_xor_fetch (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_xor_fetch." } */
kono
parents:
diff changeset
25 __atomic_or_fetch (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_or_fetch." } */
kono
parents:
diff changeset
26 __atomic_nand_fetch (a, 1, SEQ_CST); /* { dg-error "operand type ._Atomic _Bool \\*. is incompatible with argument 1 of .__atomic_nand_fetch." } */
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 /* The following are valid and must be accepted. */
kono
parents:
diff changeset
29 _Bool val = 0, ret = 0;
kono
parents:
diff changeset
30 __atomic_exchange (a, &val, &ret, SEQ_CST);
kono
parents:
diff changeset
31 __atomic_exchange_n (a, val, SEQ_CST);
kono
parents:
diff changeset
32 __atomic_compare_exchange (a, &val, &ret, !1, SEQ_CST, SEQ_CST);
kono
parents:
diff changeset
33 __atomic_compare_exchange_n (a, &val, ret, !1, SEQ_CST, SEQ_CST);
kono
parents:
diff changeset
34 __atomic_test_and_set (a, SEQ_CST);
kono
parents:
diff changeset
35 __atomic_clear (a, SEQ_CST);
kono
parents:
diff changeset
36 }
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 void test_bool (_Bool *b)
kono
parents:
diff changeset
39 {
kono
parents:
diff changeset
40 enum { SEQ_CST = __ATOMIC_SEQ_CST };
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 __atomic_fetch_add (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_fetch_add." } */
kono
parents:
diff changeset
43 __atomic_fetch_sub (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_fetch_sub." } */
kono
parents:
diff changeset
44 __atomic_fetch_and (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_fetch_and." } */
kono
parents:
diff changeset
45 __atomic_fetch_xor (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_fetch_xor." } */
kono
parents:
diff changeset
46 __atomic_fetch_or (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_fetch_or." } */
kono
parents:
diff changeset
47 __atomic_fetch_nand (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_fetch_nand." } */
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 __atomic_add_fetch (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_add_fetch." } */
kono
parents:
diff changeset
50 __atomic_sub_fetch (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_sub_fetch." } */
kono
parents:
diff changeset
51 __atomic_and_fetch (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_and_fetch." } */
kono
parents:
diff changeset
52 __atomic_xor_fetch (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_xor_fetch." } */
kono
parents:
diff changeset
53 __atomic_or_fetch (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_or_fetch." } */
kono
parents:
diff changeset
54 __atomic_nand_fetch (b, 1, SEQ_CST); /* { dg-error "operand type ._Bool \\*. is incompatible with argument 1 of .__atomic_nand_fetch." } */
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 /* The following are valid and must be accepted. */
kono
parents:
diff changeset
57 _Bool val = 0, ret = 0;
kono
parents:
diff changeset
58 __atomic_exchange (b, &val, &ret, SEQ_CST);
kono
parents:
diff changeset
59 __atomic_exchange_n (b, val, SEQ_CST);
kono
parents:
diff changeset
60 __atomic_compare_exchange (b, &val, &ret, !1, SEQ_CST, SEQ_CST);
kono
parents:
diff changeset
61 __atomic_compare_exchange_n (b, &val, ret, !1, SEQ_CST, SEQ_CST);
kono
parents:
diff changeset
62 __atomic_test_and_set (b, SEQ_CST);
kono
parents:
diff changeset
63 __atomic_clear (b, SEQ_CST);
kono
parents:
diff changeset
64 }