Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / generic_loop_messages.cpp
blobe0affd914e7d77a3e6d3a1099a0266c58b226374
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 loop' must be a for loop}}
10 #pragma omp 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 'loop' region}}
19 #pragma omp 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 'loop' region}}
28 #pragma omp 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 'loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
39 #pragma omp 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 'loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
46 #pragma omp 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 'loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
53 #pragma omp 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 loop' cannot contain more than one 'bind' clause}}
61 #pragma omp loop bind(thread) bind(thread)
62 for (i=0; i<1000; ++i) {
65 // expected-error@+2 {{expected 'teams', 'parallel' or 'thread' in OpenMP clause 'bind'}}
66 #pragma omp parallel
67 #pragma omp loop bind(other)
68 for (i=0; i<1000; ++i) {
71 #pragma omp target
73 // expected-error@+1 {{region cannot be closely nested inside 'target' region; perhaps you forget to enclose 'omp loop' directive into a teams region?}}
74 #pragma omp loop bind(teams)
75 for (i=0; i<10; ++i) {
79 // collapse clause
81 // expected-error@+4 {{expected 2 for loops after '#pragma omp loop', but found only 1}}
82 // expected-note@+1 {{as specified in 'collapse' clause}}
83 #pragma omp loop collapse(2) bind(thread)
84 for (i=0; i<1000; ++i)
85 z = i+11;
87 // expected-error@+1 {{directive '#pragma omp loop' cannot contain more than one 'collapse' clause}}
88 #pragma omp loop collapse(2) collapse(2) bind(thread)
89 for (i=0; i<1000; ++i)
90 for (j=0; j<1000; ++j)
91 z = i+j+11;
93 // order clause
95 // expected-error@+1 {{expected 'concurrent' in OpenMP clause 'order'}}
96 #pragma omp loop order(foo) bind(thread)
97 for (i=0; i<1000; ++i)
98 z = i+11;
100 // private clause
102 // expected-error@+1 {{use of undeclared identifier 'undef_var'}}
103 #pragma omp loop private(undef_var) bind(thread)
104 for (i=0; i<1000; ++i)
105 z = i+11;
107 // lastprivate
109 // A list item may not appear in a lastprivate clause unless it is the loop
110 // iteration variable of a loop that is associated with the construct.
112 // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp loop' directives}}
113 #pragma omp loop lastprivate(z) bind(thread)
114 for (i=0; i<1000; ++i) {
115 z = i+11;
118 // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp loop' directives}}
119 #pragma omp loop lastprivate(k) collapse(2) bind(thread)
120 for (i=0; i<1000; ++i)
121 for (j=0; j<1000; ++j)
122 for (k=0; k<1000; ++k)
123 z = i+j+k+11;
125 // reduction
127 // expected-error@+1 {{use of undeclared identifier 'undef_var'}}
128 #pragma omp loop reduction(+:undef_var) bind(thread)
129 for (i=0; i<1000; ++i)
130 z = i+11;
133 template <typename T, int C>
134 void templ_test(T t) {
135 T i,z;
137 // expected-error@+4 {{expected 2 for loops after '#pragma omp loop', but found only 1}}
138 // expected-note@+1 {{as specified in 'collapse' clause}}
139 #pragma omp loop collapse(C) bind(thread)
140 for (i=0; i<1000; ++i)
141 z = i+11;
143 // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp loop' directives}}
144 #pragma omp loop lastprivate(z) bind(thread)
145 for (i=0; i<1000; ++i) {
146 z = i+11;
150 void bar()
152 templ_test<int, 2>(16); // expected-note {{in instantiation of function template specialization 'templ_test<int, 2>' requested here}}