llvm-project/clang/test/SemaOpenACC/loop-loc-and-stmt.cpp
Erich Keane b0cfbfd74b
[OpenACC] Implement loop restrictions on for loops. (#115370)
OpenACC restricts the contents of a 'for' loop affected by a 'loop'
construct without a 'seq'. The loop variable must be integer, pointer,
or random-access-iterator, it must monotonically increase/decrease, and
the trip count must be computable at runtime before the function.

This patch tries to implement some of these limitations to the best of
our ability, though it causes us to be perhaps overly restrictive at the
moment. I expect we'll revisit some of these rules/add additional
supported forms of loop-variable and 'monotonically increasing' here,
but the currently enforced rules are heavily inspired by the OMP
implementation here.
2024-11-08 05:49:45 -08:00

81 lines
2.1 KiB
C++

// RUN: %clang_cc1 %s -verify -fopenacc
//
// expected-error@+1{{OpenACC construct 'loop' cannot be used here; it can only be used in a statement context}}
#pragma acc loop
// expected-error@+1{{OpenACC construct 'loop' cannot be used here; it can only be used in a statement context}}
#pragma acc loop
int foo;
struct S {
// expected-error@+1{{OpenACC construct 'loop' cannot be used here; it can only be used in a statement context}}
#pragma acc loop
int i;
void mem_func() {
// expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
// expected-note@+1{{'loop' construct is here}}
#pragma acc loop
int foo;
// expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
// expected-note@+1{{'loop' construct is here}}
#pragma acc loop
while(0);
// expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
// expected-note@+1{{'loop' construct is here}}
#pragma acc loop
do{}while(0);
// expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
// expected-note@+1{{'loop' construct is here}}
#pragma acc loop
{}
#pragma acc loop
for(int i = 0; i < 6; ++i);
int array[5];
#pragma acc loop
for(auto X : array){}
}
};
template<typename T>
void templ_func() {
// expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
// expected-note@+1{{'loop' construct is here}}
#pragma acc loop
int foo;
// expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
// expected-note@+1{{'loop' construct is here}}
#pragma acc loop
while(T{});
// expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
// expected-note@+1{{'loop' construct is here}}
#pragma acc loop
do{}while(0);
// expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
// expected-note@+1{{'loop' construct is here}}
#pragma acc loop
{}
#pragma acc loop
for(T i = 0; i < 1; ++i);
T array[5];
#pragma acc loop
for(auto X : array){}
}
void use() {
templ_func<int>();
}