Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / for_ordered_clause.cpp
blobd9dbb828f6452e5db959b0dcb3b7e8e945f2d9aa
1 // RUN: %clang_cc1 -verify -fopenmp %s
2 // RUN: %clang_cc1 -verify -fopenmp -std=c++98 %s
3 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 %s
5 // RUN: %clang_cc1 -verify -fopenmp-simd %s
6 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++98 %s
7 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 %s
9 // expected-note@* 0+{{declared here}}
10 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
12 void foo() {
15 bool foobool(int argc) {
16 return argc;
19 struct S1;
21 template <class T, typename S, int N, int ST>
22 T tmain(T argc, S **argv) {
23 #pragma omp for ordered
24 for (int i = ST; i < N; i++)
25 argv[0][i] = argv[0][i] - argv[0][i - ST];
26 #pragma omp for ordered( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
27 for (int i = ST; i < N; i++)
28 argv[0][i] = argv[0][i] - argv[0][i - ST];
29 #pragma omp for ordered() // expected-error {{expected expression}}
30 for (int i = ST; i < N; i++)
31 argv[0][i] = argv[0][i] - argv[0][i - ST];
32 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
33 // expected-error@+1 2 {{integral constant expression}} expected-note@+1 0+{{constant expression}}
34 #pragma omp for ordered(argc
35 for (int i = ST; i < N; i++)
36 argv[0][i] = argv[0][i] - argv[0][i - ST];
37 // expected-error@+1 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
38 #pragma omp for ordered(ST // expected-error {{expected ')'}} expected-note {{to match this '('}}
39 for (int i = ST; i < N; i++)
40 argv[0][i] = argv[0][i] - argv[0][i - ST];
41 #pragma omp for ordered(1)) // expected-warning {{extra tokens at the end of '#pragma omp for' are ignored}}
42 for (int i = ST; i < N; i++)
43 argv[0][i] = argv[0][i] - argv[0][i - ST];
44 #pragma omp for ordered((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'ordered' clause}}
45 for (int i = ST; i < N; i++)
46 argv[0][i] = argv[0][i] - argv[0][i - ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp for', but found only 1}}
47 // expected-error@+3 2 {{directive '#pragma omp for' cannot contain more than one 'ordered' clause}}
48 // expected-error@+2 {{argument to 'ordered' clause must be a strictly positive integer value}}
49 // expected-error@+1 2 {{integral constant expression}} expected-note@+1 0+{{constant expression}}
50 #pragma omp for ordered(foobool(argc)), ordered(true), ordered(-5)
51 for (int i = ST; i < N; i++)
52 argv[0][i] = argv[0][i] - argv[0][i - ST];
53 #pragma omp for ordered(S) // expected-error {{'S' does not refer to a value}}
54 for (int i = ST; i < N; i++)
55 argv[0][i] = argv[0][i] - argv[0][i - ST];
56 #if __cplusplus <= 199711L
57 // expected-error@+4 2 {{integral constant expression}} expected-note@+4 0+{{constant expression}}
58 #else
59 // expected-error@+2 2 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
60 #endif
61 #pragma omp for ordered(argv[1] = 2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
62 for (int i = ST; i < N; i++)
63 argv[0][i] = argv[0][i] - argv[0][i - ST];
64 #pragma omp for ordered(1)
65 for (int i = ST; i < N; i++)
66 argv[0][i] = argv[0][i] - argv[0][i - ST];
67 #pragma omp for ordered(N-1) // expected-error 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
68 for (int i = ST; i < N; i++)
69 argv[0][i] = argv[0][i] - argv[0][i - ST];
70 #pragma omp for ordered(N) // expected-error {{argument to 'ordered' clause must be a strictly positive integer value}}
71 for (T i = ST; i < N; i++)
72 argv[0][i] = argv[0][i] - argv[0][i - ST];
73 #pragma omp for ordered(2) // expected-note {{as specified in 'ordered' clause}}
74 foo(); // expected-error {{expected 2 for loops after '#pragma omp for'}}
75 #pragma omp for ordered(N) collapse(N + 2) // expected-error {{the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause}} expected-note {{parameter of the 'collapse' clause}} expected-error {{argument to 'ordered' clause must be a strictly positive integer value}}
76 for (int i = ST; i < N; i++)
77 for (int j = ST; j < N; j++)
78 for (int k = ST; k < N; k++)
79 foo();
80 return argc;
83 int main(int argc, char **argv) {
84 #pragma omp for ordered
85 for (int i = 4; i < 12; i++)
86 argv[0][i] = argv[0][i] - argv[0][i - 4];
87 #pragma omp for ordered( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
88 for (int i = 4; i < 12; i++)
89 argv[0][i] = argv[0][i] - argv[0][i - 4];
90 #pragma omp for ordered() // expected-error {{expected expression}}
91 for (int i = 4; i < 12; i++)
92 argv[0][i] = argv[0][i] - argv[0][i - 4];
93 #pragma omp for ordered(4 // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-note {{as specified in 'ordered' clause}}
94 for (int i = 4; i < 12; i++)
95 argv[0][i] = argv[0][i] - argv[0][i - 4]; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
96 #pragma omp for ordered(2 + 2)) // expected-warning {{extra tokens at the end of '#pragma omp for' are ignored}} expected-note {{as specified in 'ordered' clause}}
97 for (int i = 4; i < 12; i++)
98 argv[0][i] = argv[0][i] - argv[0][i - 4]; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
99 // expected-error@+1 {{integral constant expression}} expected-note@+1 0+{{constant expression}}
100 #pragma omp for ordered(foobool(1) > 0 ? 1 : 2)
101 for (int i = 4; i < 12; i++)
102 argv[0][i] = argv[0][i] - argv[0][i - 4];
103 // expected-error@+3 {{integral constant expression}} expected-note@+3 0+{{constant expression}}
104 // expected-error@+2 2 {{directive '#pragma omp for' cannot contain more than one 'ordered' clause}}
105 // expected-error@+1 {{argument to 'ordered' clause must be a strictly positive integer value}}
106 #pragma omp for ordered(foobool(argc)), ordered(true), ordered(-5)
107 for (int i = 4; i < 12; i++)
108 argv[0][i] = argv[0][i] - argv[0][i - 4];
109 #pragma omp for ordered(S1) // expected-error {{'S1' does not refer to a value}}
110 for (int i = 4; i < 12; i++)
111 argv[0][i] = argv[0][i] - argv[0][i - 4];
112 #if __cplusplus <= 199711L
113 // expected-error@+4 {{integral constant expression}} expected-note@+4 0+{{constant expression}}
114 #else
115 // expected-error@+2 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
116 #endif
117 #pragma omp for ordered(argv[1] = 2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
118 for (int i = 4; i < 12; i++)
119 argv[0][i] = argv[0][i] - argv[0][i - 4];
120 // expected-error@+3 {{statement after '#pragma omp for' must be a for loop}}
121 // expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, -1, -2>' requested here}}
122 #pragma omp for ordered(ordered(tmain < int, char, -1, -2 > (argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
123 foo();
124 #pragma omp for ordered(2) // expected-note {{as specified in 'ordered' clause}}
125 foo(); // expected-error {{expected 2 for loops after '#pragma omp for'}}
126 #pragma omp for ordered(0) // expected-error {{argument to 'ordered' clause must be a strictly positive integer value}}
127 for (int i = 4; i < 12; i++)
128 argv[0][i] = argv[0][i] - argv[0][i - 4];
129 #pragma omp for ordered(2) collapse(3) // expected-error {{the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause}} expected-note {{parameter of the 'collapse' clause}}
130 for (int i = 0; i < 10; i++)
131 for (int j = 0; j < 11; j++)
132 for (int k = 0; k < 12; k++)
133 foo();
134 // expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, 1, 0>' requested here}}
135 return tmain<int, char, 1, 0>(argc, argv);