Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_generic_loop_messages.cpp
blobe95c4fbb988ec0b79afce96a4bbe1d54667de897
1 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -verify -fopenmp \
2 // RUN: -Wuninitialized %s
4 void foo()
6 int i,j,k;
7 int z;
9 // expected-error@+2 {{statement after '#pragma omp target parallel loop' must be a for loop}}
10 #pragma omp target parallel loop bind(thread)
11 i = 0;
13 // OpenMP 5.1 [2.22 Nesting of regions]
15 // A barrier region may not be closely nested inside a worksharing, loop,
16 // task, taskloop, critical, ordered, atomic, or masked region.
18 // expected-error@+3 {{region cannot be closely nested inside 'target parallel loop' region}}
19 #pragma omp target parallel loop bind(thread)
20 for (i=0; i<1000; ++i) {
21 #pragma omp barrier
24 // A masked region may not be closely nested inside a worksharing, loop,
25 // atomic, task, or taskloop region.
27 // expected-error@+3 {{region cannot be closely nested inside 'target parallel loop' region}}
28 #pragma omp target parallel loop bind(thread)
29 for (i=0; i<1000; ++i) {
30 #pragma omp masked filter(2)
31 { }
34 // An ordered region that corresponds to an ordered construct without any
35 // clause or with the threads or depend clause may not be closely nested
36 // inside a critical, ordered, loop, atomic, task, or taskloop region.
38 // expected-error@+3 {{region cannot be closely nested inside 'target parallel loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
39 #pragma omp target parallel loop bind(thread)
40 for (i=0; i<1000; ++i) {
41 #pragma omp ordered
42 { }
45 // expected-error@+3 {{region cannot be closely nested inside 'target parallel loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
46 #pragma omp target parallel loop bind(thread)
47 for (i=0; i<1000; ++i) {
48 #pragma omp ordered threads
49 { }
52 // expected-error@+3 {{region cannot be closely nested inside 'target parallel loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
53 #pragma omp target parallel loop bind(thread)
54 for (i=0; i<1000; ++i) {
55 #pragma omp ordered depend(source)
58 // bind clause
60 // expected-error@+1 {{directive '#pragma omp target parallel loop' cannot contain more than one 'bind' clause}}
61 #pragma omp target parallel loop bind(thread) bind(thread)
62 for (i=0; i<1000; ++i) {
65 // expected-error@+1 {{expected 'teams', 'parallel' or 'thread' in OpenMP clause 'bind'}}
66 #pragma omp target parallel loop bind(other)
67 for (i=0; i<1000; ++i) {
70 // collapse clause
72 // expected-error@+4 {{expected 2 for loops after '#pragma omp target parallel loop', but found only 1}}
73 // expected-note@+1 {{as specified in 'collapse' clause}}
74 #pragma omp target parallel loop collapse(2) bind(thread)
75 for (i=0; i<1000; ++i)
76 z = i+11;
78 // expected-error@+1 {{directive '#pragma omp target parallel loop' cannot contain more than one 'collapse' clause}}
79 #pragma omp target parallel loop collapse(2) collapse(2) bind(thread)
80 for (i=0; i<1000; ++i)
81 for (j=0; j<1000; ++j)
82 z = i+j+11;
84 // order clause
86 // expected-error@+1 {{expected 'concurrent' in OpenMP clause 'order'}}
87 #pragma omp target parallel loop order(foo) bind(thread)
88 for (i=0; i<1000; ++i)
89 z = i+11;
91 // private clause
93 // expected-error@+1 {{use of undeclared identifier 'undef_var'}}
94 #pragma omp target parallel loop private(undef_var) bind(thread)
95 for (i=0; i<1000; ++i)
96 z = i+11;
98 // lastprivate
100 // A list item may not appear in a lastprivate clause unless it is the loop
101 // iteration variable of a loop that is associated with the construct.
103 // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp target parallel loop' directives}}
104 #pragma omp target parallel loop lastprivate(z) bind(thread)
105 for (i=0; i<1000; ++i) {
106 z = i+11;
109 // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp target parallel loop' directives}}
110 #pragma omp target parallel loop lastprivate(k) collapse(2) bind(thread)
111 for (i=0; i<1000; ++i)
112 for (j=0; j<1000; ++j)
113 for (k=0; k<1000; ++k)
114 z = i+j+k+11;
116 // reduction
118 // expected-error@+1 {{use of undeclared identifier 'undef_var'}}
119 #pragma omp target parallel loop reduction(+:undef_var) bind(thread)
120 for (i=0; i<1000; ++i)
121 z = i+11;
123 // nowait
125 // expected-error@+1 {{directive '#pragma omp target parallel loop' cannot contain more than one 'nowait' clause}}
126 #pragma omp target parallel loop nowait nowait
127 for (i=0; i<1000; ++i)
128 z = i+11;
130 // num_threads
132 // expected-error@+1 {{directive '#pragma omp target parallel loop' cannot contain more than one 'num_threads' clause}}
133 #pragma omp target parallel loop num_threads(4) num_threads(4)
134 for (i=0; i<1000; ++i)
135 z = i+11;
137 // proc_bind
139 // expected-error@+1 {{directive '#pragma omp target parallel loop' cannot contain more than one 'proc_bind' clause}}
140 #pragma omp target parallel loop proc_bind(close) proc_bind(primary)
141 for (i=0; i<1000; ++i)
142 z = i+11;
145 template <typename T, int C>
146 void templ_test(T t) {
147 T i,z;
149 // expected-error@+4 {{expected 2 for loops after '#pragma omp target parallel loop', but found only 1}}
150 // expected-note@+1 {{as specified in 'collapse' clause}}
151 #pragma omp target parallel loop collapse(C) bind(thread)
152 for (i=0; i<1000; ++i)
153 z = i+11;
155 // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp target parallel loop' directives}}
156 #pragma omp target parallel loop lastprivate(z) bind(thread)
157 for (i=0; i<1000; ++i) {
158 z = i+11;
162 void bar()
164 templ_test<int, 2>(16); // expected-note {{in instantiation of function template specialization 'templ_test<int, 2>' requested here}}