| 1 |
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++20 -fopenmp -fopenmp-version=60 -fsyntax-only -Wuninitialized -verify %s |
| 2 |
|
| 3 |
void func() { |
| 4 |
|
| 5 |
// expected-error@+2 {{statement after '#pragma omp fuse' must be a loop sequence containing canonical loops or loop-generating constructs}} |
| 6 |
#pragma omp fuse |
| 7 |
; |
| 8 |
|
| 9 |
// expected-error@+2 {{statement after '#pragma omp fuse' must be a for loop}} |
| 10 |
#pragma omp fuse |
| 11 |
{int bar = 0;} |
| 12 |
|
| 13 |
// expected-error@+4 {{statement after '#pragma omp fuse' must be a for loop}} |
| 14 |
#pragma omp fuse |
| 15 |
{ |
| 16 |
for(int i = 0; i < 10; ++i); |
| 17 |
int x = 2; |
| 18 |
} |
| 19 |
|
| 20 |
// expected-error@+2 {{statement after '#pragma omp fuse' must be a loop sequence containing canonical loops or loop-generating constructs}} |
| 21 |
#pragma omp fuse |
| 22 |
#pragma omp for |
| 23 |
for (int i = 0; i < 7; ++i) |
| 24 |
; |
| 25 |
|
| 26 |
{ |
| 27 |
// expected-error@+2 {{expected statement}} |
| 28 |
#pragma omp fuse |
| 29 |
} |
| 30 |
|
| 31 |
// expected-warning@+1 {{extra tokens at the end of '#pragma omp fuse' are ignored}} |
| 32 |
#pragma omp fuse foo |
| 33 |
{ |
| 34 |
for (int i = 0; i < 7; ++i) |
| 35 |
; |
| 36 |
for(int j = 0; j < 100; ++j); |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
// expected-error@+1 {{unexpected OpenMP clause 'final' in directive '#pragma omp fuse'}} |
| 42 |
#pragma omp fuse final(0) |
| 43 |
{ |
| 44 |
for (int i = 0; i < 7; ++i) |
| 45 |
; |
| 46 |
for(int j = 0; j < 100; ++j); |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
//expected-error@+3 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}} |
| 51 |
#pragma omp fuse |
| 52 |
{ |
| 53 |
for(int i = 0; i < 10; i*=2) { |
| 54 |
; |
| 55 |
} |
| 56 |
for(int j = 0; j < 100; ++j); |
| 57 |
} |
| 58 |
|
| 59 |
//expected-error@+2 {{loop sequence after '#pragma omp fuse' must contain at least 1 canonical loop or loop-generating construct}} |
| 60 |
#pragma omp fuse |
| 61 |
{} |
| 62 |
|
| 63 |
//expected-error@+3 {{statement after '#pragma omp fuse' must be a for loop}} |
| 64 |
#pragma omp fuse |
| 65 |
{ |
| 66 |
#pragma omp unroll full |
| 67 |
for(int i = 0; i < 10; ++i); |
| 68 |
|
| 69 |
for(int j = 0; j < 10; ++j); |
| 70 |
} |
| 71 |
|
| 72 |
//expected-warning@+2 {{looprange clause selects a single loop, resulting in redundant fusion}} |
| 73 |
#pragma omp fuse |
| 74 |
{ |
| 75 |
for(int i = 0; i < 10; ++i); |
| 76 |
} |
| 77 |
|
| 78 |
//expected-warning@+1 {{looprange clause selects a single loop, resulting in redundant fusion}} |
| 79 |
#pragma omp fuse looprange(1, 1) |
| 80 |
{ |
| 81 |
for(int i = 0; i < 10; ++i); |
| 82 |
for(int j = 0; j < 100; ++j); |
| 83 |
} |
| 84 |
|
| 85 |
//expected-error@+1 {{argument to 'looprange' clause must be a strictly positive integer value}} |
| 86 |
#pragma omp fuse looprange(1, -1) |
| 87 |
{ |
| 88 |
for(int i = 0; i < 10; ++i); |
| 89 |
for(int j = 0; j < 100; ++j); |
| 90 |
} |
| 91 |
|
| 92 |
//expected-error@+1 {{argument to 'looprange' clause must be a strictly positive integer value}} |
| 93 |
#pragma omp fuse looprange(1, 0) |
| 94 |
{ |
| 95 |
for(int i = 0; i < 10; ++i); |
| 96 |
for(int j = 0; j < 100; ++j); |
| 97 |
} |
| 98 |
|
| 99 |
const int x = 1; |
| 100 |
constexpr int y = 4; |
| 101 |
//expected-error@+1 {{looprange clause selects loops from 1 to 4 but this exceeds the number of loops (3) in the loop sequence}} |
| 102 |
#pragma omp fuse looprange(x,y) |
| 103 |
{ |
| 104 |
for(int i = 0; i < 10; ++i); |
| 105 |
for(int j = 0; j < 100; ++j); |
| 106 |
for(int k = 0; k < 50; ++k); |
| 107 |
} |
| 108 |
|
| 109 |
//expected-error@+1 {{looprange clause selects loops from 1 to 420 but this exceeds the number of loops (3) in the loop sequence}} |
| 110 |
#pragma omp fuse looprange(1,420) |
| 111 |
{ |
| 112 |
for(int i = 0; i < 10; ++i); |
| 113 |
for(int j = 0; j < 100; ++j); |
| 114 |
for(int k = 0; k < 50; ++k); |
| 115 |
} |
| 116 |
|
| 117 |
//expected-error@+1 {{looprange clause selects loops from 1 to 6 but this exceeds the number of loops (5) in the loop sequence}} |
| 118 |
#pragma omp fuse looprange(1,6) |
| 119 |
{ |
| 120 |
for(int i = 0; i < 10; ++i); |
| 121 |
for(int j = 0; j < 100; ++j); |
| 122 |
for(int k = 0; k < 50; ++k); |
| 123 |
// This fusion results in 2 loops |
| 124 |
#pragma omp fuse looprange(1,2) |
| 125 |
{ |
| 126 |
for(int i = 0; i < 10; ++i); |
| 127 |
for(int j = 0; j < 100; ++j); |
| 128 |
for(int k = 0; k < 50; ++k); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
//expected-error@+1 {{looprange clause selects loops from 2 to 4 but this exceeds the number of loops (3) in the loop sequence}} |
| 133 |
#pragma omp fuse looprange(2,3) |
| 134 |
{ |
| 135 |
#pragma omp unroll partial(2) |
| 136 |
for(int i = 0; i < 10; ++i); |
| 137 |
|
| 138 |
#pragma omp reverse |
| 139 |
for(int j = 0; j < 10; ++j); |
| 140 |
|
| 141 |
#pragma omp fuse |
| 142 |
{ |
| 143 |
{ |
| 144 |
#pragma omp reverse |
| 145 |
for(int j = 0; j < 10; ++j); |
| 146 |
} |
| 147 |
for(int k = 0; k < 50; ++k); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
// In a template context, but expression itself not instantiation-dependent |
| 153 |
template <typename T> |
| 154 |
static void templated_func() { |
| 155 |
|
| 156 |
//expected-warning@+1 {{looprange clause selects a single loop, resulting in redundant fusion}} |
| 157 |
#pragma omp fuse looprange(2,1) |
| 158 |
{ |
| 159 |
for(int i = 0; i < 10; ++i); |
| 160 |
for(int j = 0; j < 100; ++j); |
| 161 |
for(int k = 0; k < 50; ++k); |
| 162 |
} |
| 163 |
|
| 164 |
//expected-error@+1 {{looprange clause selects loops from 3 to 5 but this exceeds the number of loops (3) in the loop sequence}} |
| 165 |
#pragma omp fuse looprange(3,3) |
| 166 |
{ |
| 167 |
for(int i = 0; i < 10; ++i); |
| 168 |
for(int j = 0; j < 100; ++j); |
| 169 |
for(int k = 0; k < 50; ++k); |
| 170 |
} |
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
template <int V> |
| 175 |
static void templated_func_value_dependent() { |
| 176 |
|
| 177 |
//expected-warning@+1 {{looprange clause selects a single loop, resulting in redundant fusion}} |
| 178 |
#pragma omp fuse looprange(V,1) |
| 179 |
{ |
| 180 |
for(int i = 0; i < 10; ++i); |
| 181 |
for(int j = 0; j < 100; ++j); |
| 182 |
for(int k = 0; k < 50; ++k); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
template <typename T> |
| 187 |
static void templated_func_type_dependent() { |
| 188 |
constexpr T s = 1; |
| 189 |
|
| 190 |
//expected-error@+1 {{argument to 'looprange' clause must be a strictly positive integer value}} |
| 191 |
#pragma omp fuse looprange(s,s-1) |
| 192 |
{ |
| 193 |
for(int i = 0; i < 10; ++i); |
| 194 |
for(int j = 0; j < 100; ++j); |
| 195 |
for(int k = 0; k < 50; ++k); |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
void template_inst() { |
| 201 |
// expected-note@+1 {{in instantiation of function template specialization 'templated_func<int>' requested here}} |
| 202 |
templated_func<int>(); |
| 203 |
// expected-note@+1 {{in instantiation of function template specialization 'templated_func_value_dependent<1>' requested here}} |
| 204 |
templated_func_value_dependent<1>(); |
| 205 |
// expected-note@+1 {{in instantiation of function template specialization 'templated_func_type_dependent<int>' requested here}} |
| 206 |
templated_func_type_dependent<int>(); |
| 207 |
} |
| 208 |
|
| 209 |
|