]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/c-c++-common/gomp/critical-hint-1.c
OpenMP: Fixes for omp critical + hint
[thirdparty/gcc.git] / gcc / testsuite / c-c++-common / gomp / critical-hint-1.c
1 #include <omp.h>
2
3 void
4 example_criticial ()
5 {
6 int a, b;
7 #pragma omp parallel for
8 for (int i = 0; i < 10; ++i)
9 {
10 #pragma omp critical hint(omp_sync_hint_none) /* OK */
11 a += i;
12 #pragma omp critical (HASH) hint(omp_sync_hint_none) /* OK */
13 a += i;
14 #pragma omp critical (HASH2) hint(omp_sync_hint_uncontended) /* OK */
15 a += i;
16 #pragma omp critical (HASH3) hint(omp_sync_hint_contended) /* OK */
17 a += i;
18 #pragma omp critical (HASH4) hint(omp_sync_hint_speculative) /* OK */
19 a += i;
20 #pragma omp critical (HASH5) hint(omp_sync_hint_nonspeculative) /* OK */
21 a += i;
22 #pragma omp critical (HASH6) hint(omp_sync_hint_contended + omp_sync_hint_speculative) /* OK */
23 a += i;
24 #pragma omp critical (HASH6) hint(omp_sync_hint_contended | omp_sync_hint_speculative) /* OK */
25 a += i;
26
27 /* Accepted but invalid: different hint for same name. */
28 #pragma omp critical (HASH6) hint(omp_sync_hint_uncontended + omp_sync_hint_speculative)
29 a += i;
30 /* Accepted but invalid: Some random integer expr. */
31 #pragma omp critical (HASH) hint(omp_sync_hint_speculative + 1 + 2)
32 a += i;
33
34 #pragma omp critical (HASH) hint(-3) /* { dg-error "expected constant integer expression" } */
35 a += i;
36 #pragma omp critical (HASH2) hint(b) /* { dg-error "constant integer expression" } */
37 a += i;
38 /*
39 Fails with gcc as 'expected identifier' and
40 with g++ as "clause requires a name, except when 'omp_sync_hint_none'"
41 #pragma omp critical () hint(omp_sync_hint_speculative)
42 a += i;
43 */
44 #pragma omp critical hint(omp_sync_hint_speculative) /* { dg-error "with 'hint' clause requires a name, except when 'omp_sync_hint_none' is used" } */
45 a += i;
46 }
47 }