| 1 |
// { dg-do compile } |
| 2 |
// { dg-additional-options "-fdump-tree-gimple" } |
| 3 |
|
| 4 |
// Check that expressions in metadirectives are handled correctly in template |
| 5 |
// functions when they are value-dependent and/or type-dependent. |
| 6 |
|
| 7 |
int x; |
| 8 |
|
| 9 |
// Type-dependent expression. |
| 10 |
template <typename T> |
| 11 |
void |
| 12 |
f1 (void) |
| 13 |
{ |
| 14 |
#pragma omp metadirective \ |
| 15 |
when (user={condition(static_cast<T> (1.0))}: target) |
| 16 |
x = 1; |
| 17 |
} |
| 18 |
|
| 19 |
// Value-dependent expression. |
| 20 |
template <int N> |
| 21 |
void |
| 22 |
f2 (void) |
| 23 |
{ |
| 24 |
#pragma omp metadirective \ |
| 25 |
when (user={condition(N)}: target) |
| 26 |
x = 2; |
| 27 |
} |
| 28 |
|
| 29 |
// Both type- and value-dependent. |
| 30 |
template <typename T, T N> |
| 31 |
void |
| 32 |
f3 (void) |
| 33 |
{ |
| 34 |
#pragma omp metadirective \ |
| 35 |
when (user={condition(N)}: target) |
| 36 |
x = 3; |
| 37 |
} |
| 38 |
|
| 39 |
// Expression is itself a template instantiation. |
| 40 |
template <typename T, T N> |
| 41 |
bool |
| 42 |
test (void) |
| 43 |
{ |
| 44 |
return N != 0; |
| 45 |
} |
| 46 |
|
| 47 |
template <typename T, T N> |
| 48 |
void |
| 49 |
f4 (void) |
| 50 |
{ |
| 51 |
#pragma omp metadirective \ |
| 52 |
when (user={condition(test<T, N> ())}: teams) |
| 53 |
x = 4; |
| 54 |
} |
| 55 |
|
| 56 |
int |
| 57 |
main (void) |
| 58 |
{ |
| 59 |
f1 <int> (); |
| 60 |
f2 <1> (); |
| 61 |
f2 <0> (); |
| 62 |
f3 <int, 1> (); |
| 63 |
f3 <int, 0> (); |
| 64 |
f4 <int, 1> (); |
| 65 |
f4 <int, 0> (); |
| 66 |
} |
| 67 |
|
| 68 |
// Each of f1..f3 should be instantiated once with a condition expression |
| 69 |
// that is a constant 1, producing a target construct. The metadirective in |
| 70 |
// f4 has a non-constant condition expression, so both instantiations will |
| 71 |
// produce a conditional including an alternative including a teams construct. |
| 72 |
|
| 73 |
// { dg-final { scan-tree-dump-times "pragma omp target" 3 "gimple" } } |
| 74 |
// { dg-final { scan-tree-dump-times "pragma omp teams" 2 "gimple" } } |