Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions flang/lib/Semantics/check-acc-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ void AccStructureChecker::Enter(const parser::OpenACCCacheConstruct &x) {
const auto &verbatim = std::get<parser::Verbatim>(x.t);
PushContextAndClauseSets(verbatim.source, llvm::acc::Directive::ACCD_cache);
SetContextDirectiveSource(verbatim.source);
if (loopNestLevel == 0) {
context_.Say(verbatim.source,
"The CACHE directive must be inside a loop"_err_en_US);
}
}
void AccStructureChecker::Leave(const parser::OpenACCCacheConstruct &x) {
dirContext_.pop_back();
Expand Down Expand Up @@ -655,6 +659,14 @@ void AccStructureChecker::Enter(const parser::SeparateModuleSubprogram &) {
declareSymbols.clear();
}

void AccStructureChecker::Enter(const parser::DoConstruct &) {
++loopNestLevel;
}

void AccStructureChecker::Leave(const parser::DoConstruct &) {
--loopNestLevel;
}

llvm::StringRef AccStructureChecker::getDirectiveName(
llvm::acc::Directive directive) {
return llvm::acc::getOpenACCDirectiveName(directive);
Expand Down
3 changes: 3 additions & 0 deletions flang/lib/Semantics/check-acc-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class AccStructureChecker
void Enter(const parser::SubroutineSubprogram &);
void Enter(const parser::FunctionSubprogram &);
void Enter(const parser::SeparateModuleSubprogram &);
void Enter(const parser::DoConstruct &);
void Leave(const parser::DoConstruct &);

#define GEN_FLANG_CLAUSE_CHECK_ENTER
#include "llvm/Frontend/OpenACC/ACC.inc"
Expand All @@ -88,6 +90,7 @@ class AccStructureChecker
llvm::StringRef getDirectiveName(llvm::acc::Directive directive) override;

llvm::SmallDenseSet<Symbol *> declareSymbols;
unsigned loopNestLevel = 0;
};

} // namespace Fortran::semantics
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Semantics/OpenACC/acc-cache-validity.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ program openacc_cache_validity
type(atype), dimension(10) :: ta
real(8), dimension(N) :: a

do i = 1, N

!$acc cache(a(i))
!$acc cache(a(1:2,3:4))
!$acc cache(a)
Expand All @@ -40,4 +42,9 @@ program openacc_cache_validity
!ERROR: Only array element or subarray are allowed in CACHE directive
!$acc cache(/i/)

end do

!ERROR: The CACHE directive must be inside a loop
!$acc cache(a)

end program openacc_cache_validity