xref: /llvm-project/flang/test/Semantics/OpenMP/atomic-hint-clause.f90 (revision 00ab44ee66dbcf0d32819dbc6e4eefd1b7c48dfa)
1! REQUIRES: openmp_runtime
2
3! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=50
4! Semantic checks on hint clauses, as they appear on atomic constructs
5
6program sample
7    use omp_lib
8    integer :: x, y
9    logical :: z
10    real :: k
11    integer :: p(1)
12    integer, parameter :: a = 1
13    !$omp atomic hint(1) write
14        y = 2
15
16    !$omp atomic read hint(2)
17        y = x
18
19    !ERROR: Hint clause value is not a valid OpenMP synchronization value
20    !$omp atomic hint(3)
21        y = y + 10
22
23    !$omp atomic update hint(5)
24        y = x + y
25
26    !ERROR: Hint clause value is not a valid OpenMP synchronization value
27    !$omp atomic hint(7) capture
28        y = x
29        x = y
30    !$omp end atomic
31
32    !ERROR: Hint clause must have non-negative constant integer expression
33    !ERROR: Must be a constant value
34    !$omp atomic update hint(x)
35        y = y * 1
36
37    !$omp atomic read hint(4)
38        y = x
39
40    !$omp atomic hint(8)
41        x = x * y
42
43    !$omp atomic write hint(omp_sync_hint_uncontended)
44        x = 10 * y
45
46    !$omp atomic hint(omp_lock_hint_speculative)
47        x = y + x
48
49    !ERROR: Hint clause must have non-negative constant integer expression
50    !ERROR: Must be a constant value
51    !$omp atomic hint(omp_sync_hint_uncontended + omp_sync_hint) read
52        y = x
53
54    !$omp atomic hint(omp_sync_hint_nonspeculative)
55        y = y * 9
56
57    !$omp atomic hint(omp_sync_hint_none) read
58        y = x
59
60    !$omp atomic read hint(omp_sync_hint_uncontended + omp_lock_hint_speculative)
61        y = x
62
63    !$omp atomic hint(omp_lock_hint_nonspeculative + omp_lock_hint_uncontended)
64        x = x * y
65
66    !$omp atomic write hint(omp_lock_hint_contended + omp_sync_hint_speculative)
67        x = 10 * y
68
69    !$omp atomic hint(omp_lock_hint_contended + omp_sync_hint_nonspeculative)
70        x = y + x
71
72    !ERROR: Hint clause value is not a valid OpenMP synchronization value
73    !$omp atomic hint(omp_sync_hint_uncontended + omp_sync_hint_contended) read
74        y = x
75
76    !ERROR: Hint clause value is not a valid OpenMP synchronization value
77    !$omp atomic hint(omp_sync_hint_nonspeculative + omp_lock_hint_speculative)
78        y = y * 9
79
80    !ERROR: Hint clause must have non-negative constant integer expression
81    !$omp atomic hint(1.0) read
82        y = x
83
84    !ERROR: Hint clause must have non-negative constant integer expression
85    !ERROR: Operands of + must be numeric; have LOGICAL(4) and INTEGER(4)
86    !$omp atomic hint(z + omp_sync_hint_nonspeculative) read
87        y = x
88
89    !ERROR: Hint clause must have non-negative constant integer expression
90    !ERROR: Must be a constant value
91    !$omp atomic hint(k + omp_sync_hint_speculative) read
92        y = x
93
94    !ERROR: Hint clause must have non-negative constant integer expression
95    !ERROR: Must be a constant value
96    !$omp atomic hint(p(1) + omp_sync_hint_uncontended) write
97        x = 10 * y
98
99    !$omp atomic write hint(a)
100    !ERROR: RHS expression on atomic assignment statement cannot access 'x'
101        x = y + x
102
103    !$omp atomic hint(abs(-1)) write
104        x = 7
105
106    !$omp atomic hint(omp_sync_hint_uncontended + omp_sync_hint_uncontended + omp_sync_hint_speculative) write
107        x = 7
108end program
109