llvm-project/clang/test/SemaOpenACC/cache-warn-invalid-varloc.cpp
erichkeane 438863a09e [OpenACC][Sema] Implement warning for 'cache' invalid var ref
The 'cache' construct is lowered as marking the acc.loop in ACC MLIR.
This results in any variable references that are not inside of the
acc.loop being invalid.  This patch adds a warning to that effect, and
ensures that the variable references won't be added to the AST during
parsing so we don't try to lower them.

This results in loss of instantiation-diagnostics for these, however
that seems like an acceptable consequence to ignoring it.
2025-07-03 07:13:30 -07:00

30 lines
861 B
C++

// RUN: %clang_cc1 %s -fopenacc -verify
void foo() {
int Array[5];
// expected-warning@+1 2{{OpenACC variable in 'cache' directive was not declared outside of the associated 'loop' directive; directive has no effect}}
#pragma acc cache(readonly:Array[1], Array[1:2])
}
void foo2() {
#pragma acc loop
for(int i = 0; i < 5; ++i) {
int Array[5];
// expected-warning@+1 2{{OpenACC variable in 'cache' directive was not declared outside of the associated 'loop' directive; directive has no effect}}
#pragma acc cache(readonly:Array[1], Array[1:2])
}
}
template<typename T>
void foo3() {
T Array[5];
// expected-warning@+1 2{{OpenACC variable in 'cache' directive was not declared outside of the associated 'loop' directive; directive has no effect}}
#pragma acc cache(readonly:Array[1], Array[1:2])
}
void Inst() {
foo3<int>();
}