Clang Project

clang_source_code/test/OpenMP/target_teams_distribute_simd_collapse_messages.cpp
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
4
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
8
9void foo() {
10}
11
12#if __cplusplus >= 201103L
13// expected-note@+2 4 {{declared here}}
14#endif
15bool foobool(int argc) {
16  return argc;
17}
18
19struct S1; // expected-note {{declared here}}
20
21template <class T, typename S, int N, int ST> // expected-note {{declared here}}
22T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
23#pragma omp target teams distribute simd collapse // expected-error {{expected '(' after 'collapse'}}
24  for (int i = ST; i < N; i++)
25    argv[0][i] = argv[0][i] - argv[0][i-ST];
26
27#pragma omp target teams distribute simd collapse ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
28  for (int i = ST; i < N; i++)
29
30    argv[0][i] = argv[0][i] - argv[0][i-ST];
31#pragma omp target teams distribute simd collapse () // expected-error {{expected expression}}
32  for (int i = ST; i < N; i++)
33    argv[0][i] = argv[0][i] - argv[0][i-ST];
34
35// expected-error@+3 {{expected ')'}} expected-note@+3 {{to match this '('}}
36// expected-error@+2 2 {{expression is not an integral constant expression}}
37// expected-note@+1 2 {{read of non-const variable 'argc' is not allowed in a constant expression}}
38#pragma omp target teams distribute simd collapse (argc
39  for (int i = ST; i < N; i++)
40    argv[0][i] = argv[0][i] - argv[0][i-ST];
41
42// expected-error@+1 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
43#pragma omp target teams distribute simd collapse (ST // expected-error {{expected ')'}} expected-note {{to match this '('}}
44  for (int i = ST; i < N; i++)
45    argv[0][i] = argv[0][i] - argv[0][i-ST];
46
47#pragma omp target teams distribute simd collapse (1)) // expected-warning {{extra tokens at the end of '#pragma omp target teams distribute simd' are ignored}}
48  for (int i = ST; i < N; i++)
49    argv[0][i] = argv[0][i] - argv[0][i-ST];
50
51#pragma omp target teams distribute simd collapse ((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'collapse' clause}}
52  for (int i = ST; i < N; i++)
53    argv[0][i] = argv[0][i] - argv[0][i-ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp target teams distribute simd', but found only 1}}
54
55// expected-error@+6 2 {{directive '#pragma omp target teams distribute simd' cannot contain more than one 'collapse' clause}}
56// expected-error@+5 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
57// expected-error@+4 2 {{expression is not an integral constant expression}}
58#if __cplusplus >= 201103L
59// expected-note@+2 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
60#endif
61#pragma omp target teams distribute simd collapse (foobool(argc)), collapse (true), collapse (-5)
62  for (int i = ST; i < N; i++)
63    argv[0][i] = argv[0][i] - argv[0][i-ST];
64
65#pragma omp distribute collapse (S) // expected-error {{'S' does not refer to a value}}
66  for (int i = ST; i < N; i++)
67    argv[0][i] = argv[0][i] - argv[0][i-ST];
68
69#if __cplusplus <= 199711L
70  // expected-error@+4 2 {{expression is not an integral constant expression}}
71#else
72  // expected-error@+2 2 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
73#endif
74#pragma omp target teams distribute simd collapse (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
75  for (int i = ST; i < N; i++)
76    argv[0][i] = argv[0][i] - argv[0][i-ST];
77
78#pragma omp target teams distribute simd collapse (1)
79  for (int i = ST; i < N; i++)
80    argv[0][i] = argv[0][i] - argv[0][i-ST];
81
82#pragma omp target teams distribute simd collapse (N) // expected-error {{argument to 'collapse' clause must be a strictly positive integer value}}
83  for (T i = ST; i < N; i++)
84    argv[0][i] = argv[0][i] - argv[0][i-ST];
85
86#pragma omp target teams distribute simd collapse (2) // expected-note {{as specified in 'collapse' clause}}
87  foo(); // expected-error {{expected 2 for loops after '#pragma omp target teams distribute simd'}}
88  return argc;
89}
90
91int main(int argc, char **argv) {
92#pragma omp target teams distribute simd collapse // expected-error {{expected '(' after 'collapse'}}
93  for (int i = 4; i < 12; i++)
94    argv[0][i] = argv[0][i] - argv[0][i-4];
95
96#pragma omp target teams distribute simd collapse ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
97  for (int i = 4; i < 12; i++)
98    argv[0][i] = argv[0][i] - argv[0][i-4];
99
100#pragma omp target teams distribute simd collapse () // expected-error {{expected expression}}
101  for (int i = 4; i < 12; i++)
102    argv[0][i] = argv[0][i] - argv[0][i-4];
103
104#pragma omp target teams distribute simd collapse (4 // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-note {{as specified in 'collapse' clause}}
105  for (int i = 4; i < 12; i++)
106    argv[0][i] = argv[0][i] - argv[0][i-4]; // expected-error {{expected 4 for loops after '#pragma omp target teams distribute simd', but found only 1}}
107
108#pragma omp target teams distribute simd collapse (2+2)) // expected-warning {{extra tokens at the end of '#pragma omp target teams distribute simd' are ignored}} expected-note {{as specified in 'collapse' clause}}
109  for (int i = 4; i < 12; i++)
110    argv[0][i] = argv[0][i] - argv[0][i-4]; // expected-error {{expected 4 for loops after '#pragma omp target teams distribute simd', but found only 1}}
111
112#if __cplusplus >= 201103L
113  // expected-note@+2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
114#endif
115#pragma omp target teams distribute simd collapse (foobool(1) > 0 ? 1 : 2) // expected-error {{expression is not an integral constant expression}}
116  for (int i = 4; i < 12; i++)
117    argv[0][i] = argv[0][i] - argv[0][i-4];
118
119// expected-error@+6 {{expression is not an integral constant expression}}
120// expected-error@+5 2 {{directive '#pragma omp target teams distribute simd' cannot contain more than one 'collapse' clause}}
121// expected-error@+4 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
122#if __cplusplus >= 201103L
123// expected-note@+2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
124#endif
125#pragma omp target teams distribute simd collapse (foobool(argc)), collapse (true), collapse (-5)
126  for (int i = 4; i < 12; i++)
127    argv[0][i] = argv[0][i] - argv[0][i-4];
128
129#pragma omp target teams distribute simd collapse (S1) // expected-error {{'S1' does not refer to a value}}
130  for (int i = 4; i < 12; i++)
131    argv[0][i] = argv[0][i] - argv[0][i-4];
132
133#if __cplusplus >= 201103L
134  // expected-error@+4 {{integral constant expression must have integral or unscoped enumeration type, not 'char *'}}
135#else
136  // expected-error@+2 {{expression is not an integral constant expression}}
137#endif
138#pragma omp target teams distribute simd collapse (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
139  for (int i = 4; i < 12; i++)
140    argv[0][i] = argv[0][i] - argv[0][i-4];
141
142// expected-error@+3 {{statement after '#pragma omp target teams distribute simd' must be a for loop}}
143// expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, -1, -2>' requested here}}
144#pragma omp target teams distribute simd collapse(collapse(tmain<int, char, -1, -2>(argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
145  foo();
146
147#pragma omp target teams distribute simd collapse (2) // expected-note {{as specified in 'collapse' clause}}
148  foo(); // expected-error {{expected 2 for loops after '#pragma omp target teams distribute simd'}}
149
150// expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, 1, 0>' requested here}}
151  return tmain<int, char, 1, 0>(argc, argv);
152}
153
154